Skip to main content
Solved

How to select specific elements with XMLUpdater?

  • July 1, 2022
  • 2 replies
  • 74 views

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

debbiatsafe
Safer
Forum|alt.badge.img+21
  • Safer
  • 648 replies
  • 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
  • 15 replies
  • July 8, 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.

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