Solved

How to select specific elements with XMLUpdater?


Badge

Hello, 

I have to update DATE value in XML file and I use XMLUpdater transformer. It works perfect if it is only one date value.

I have problems updating date field for coleListValue="publication" in the situation that shows the following example:

 

           <CI_Citation>
 
               <date>
                  <CI_Date>
                     <date><gco:Date>2006-07-01</gco:Date></date>
                     <dateType<CI_DateTypeCode codeList="myCodelists.xml" codeListValue="creation"/></dateType>
                  </CI_Date>
               </date>
 
               <date>
                  <CI_Date>
                     <date><gco:Date>2014-07-11</gco:Date></date>
                     <dateType><CI_DateTypeCode codeList="myCodelists.xml" codeListValue="revision"/></dateType>
                  </CI_Date>
               </date>
 
               <date>
                  <CI_Date>
                     <date><gco:Date>2016-03-17</gco:Date></date>
                     <dateType><CI_DateTypeCode codeList="myCodelists.xml" codeListValue="revision"/></dateType>
                  </CI_Date>
               </date>
 
               <date>
                  <CI_Date>
                     <date><gco:Date>2020-01-22</gco:Date></date>
                     <dateType><CI_DateTypeCode codeList="myCodelists.xml" codeListValue="publication"/></dateType>
                  </CI_Date>
               </date>
 
            </CI_Citation>

 

 

I have checked information at [1] and I have tried some solutions like [2] but nothing works, could you give some advice?

 

[1] http://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Transformers/Transformers/xmlupdater.htm

[2] XML path = /MD_DataIdentification id="ID0003"/citation/CI_Citation/date/CI_Date/datetype/CI_DateTypeCode[@codeListValue="publication"]/gco:Date

icon

Best answer by debbiatsafe 5 July 2022, 19:51

View original

2 replies

Userlevel 3
Badge +17

Hello @gerard

The XPath you shared does not work for the structure of your XML file. The XPath selects the node CI_DateTypeCode where the codeListValue attribute is "publication" and this part works. However, gco:Date is not a child of this node. 

In your case, you would want to use the ancestor axes to update the gco:Date node:

//CI_Date/dateType/CI_DateTypeCode[@codeListValue='publication']/ancestor::CI_Date/date/gco:Date

Note that I have removed /MD_DataIdentification id="ID0003"/citation/ from your XPath as those are not included in the XML snippet.

Badge

Hello @gerard

The XPath you shared does not work for the structure of your XML file. The XPath selects the node CI_DateTypeCode where the codeListValue attribute is "publication" and this part works. However, gco:Date is not a child of this node. 

In your case, you would want to use the ancestor axes to update the gco:Date node:

//CI_Date/dateType/CI_DateTypeCode[@codeListValue='publication']/ancestor::CI_Date/date/gco:Date

Note that I have removed /MD_DataIdentification id="ID0003"/citation/ from your XPath as those are not included in the XML snippet.

Thanks a lot @debbiatsafe​, as you said /ancestor is the solution. Thanks!

Reply