Question

Get the Text of Element without Child Element

  • 4 March 2016
  • 4 replies
  • 17 views

Badge

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

Userlevel 2
Badge +16

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

I have highlighted them in the picture:

Badge

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?

Userlevel 2
Badge +16

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.

Badge

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

Reply