Skip to main content
Question

Get the Text of Element without Child Element


Forum|alt.badge.img

Hello, I have an element which contains child elements but I only want to extract the text of the element ignoring all the child elements.

Here is my example :

 

<list_item>

 

<paragraph>A wreck exists in position

 

<location>America>

 

</location>

 

</paragraph>

 

</list_item>

What I would like to extract is A wreck exists in position.

Usually I use the Attribute Exposer but in this case it is not workingbecause the closing tag of the paragraph is after the location.

What transformer should I sue in this case?

Thanks for you help.

4 replies

erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • March 4, 2016

The XML Reader has two parameters that can help you skip certain XML fragments.

I have highlighted them in the picture:


Forum|alt.badge.img
  • Author
  • March 4, 2016

Thanks, I tried it but it is still not working. By the way what I've posted is only a part of the xml file. So I use the xml fragmenter already a lot earlier in my script and somewhere else in my script I want to extract the location as well so I don't really want to exclude the location.Do you have any other ideas?


erik_jan
Contributor
Forum|alt.badge.img+17
  • Contributor
  • March 4, 2016

You could always query the xml_fragment attribute using the XMLXQueryExtractor to extract portions of the XML fragment into new feature attributes. So by excluding the location from the attribute flattening it will remain part of the xml_fragment and it can be extracted using XQuery.


Forum|alt.badge.img
  • Author
  • March 4, 2016

Thanks. Finally it is working using XMLXQueryExtractor and the following expression: //paragraph/text()[1]


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