Skip to main content
Solved

How to select specific elements with XMLUpdater?


gerard
Participant
Forum|alt.badge.img

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

Best answer by debbiatsafe

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.

View original
Did this help you find an answer to your question?

2 replies

debbiatsafe
Safer
Forum|alt.badge.img+20
  • Safer
  • Best Answer
  • July 5, 2022

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.


gerard
Participant
Forum|alt.badge.img
  • Author
  • Participant
  • July 8, 2022
debbiatsafe wrote:

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!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings