# Return raw XML subset string from an Xpath query

**URL:** <https://forum.cloverdx.com/t/return-raw-xml-subset-string-from-an-xpath-query/1256>\
**Category:** CloverDX Platform\
**Created:** [August 16, 2013, 12:00am UTC](https://forum.cloverdx.com/t/return-raw-xml-subset-string-from-an-xpath-query/1256 "2013-08-16T00:00:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chathaway](https://avatars.discourse-cdn.com/v4/letter/c/b5e925/32.png) [@chathaway](https://forum.cloverdx.com/u/chathaway)\
**Post date:** [August 16, 2013, 12:00am UTC](https://forum.cloverdx.com/t/return-raw-xml-subset-string-from-an-xpath-query/1256/1 "2013-08-16T00:00:00Z")

</div>

I have an HTML document that I am extracting elements out of with XPath. I’m trying to work out how to extract the full HTML branch of a given set of

 tags so that I can process them further in subsequent graph nodes.

I see a similar note posted for doing this in PHP but I am not familiar with how to use this language:  
[http://stackoverflow.com/questions/1534 … ery-in-php](http://stackoverflow.com/questions/15343229/return-raw-xml-from-xpath-query-in-php)

In case it helps, this is the Mapping syntax i am currently using which extracts hyperlinks and descriptions from each DIV where class=‘details’:  
_\<Context_  
_xpath=“//DIV[@class=‘details’]”_  
_outPort=“0” \>_  
_\<Mapping_  
_xpath=“./DIV[@class=‘vehicle’]//A/@href”_  
_cloverField=“Record\_TagA\_href”/\>_  
_\<Mapping_  
_xpath=“./DIV[@class=‘vehicle’]//A”_  
_cloverField=“Record\_TagA”/\>_  
_\<Mapping_  
_xpath=“./DIV[@class=‘vehicle’]//H5”_  
_cloverField=“Record\_TagH5”/\>_  
_\<Mapping_  
_xpath=“.//UL[@class=‘specifics’]”_  
_cloverField=“Record\_TagULspecifics”/\>_

Instead I would like a full string of each HTML DIV node where class=‘details’ stripping out everything else e.g. just leaving:

**…**.

I originally tried in a standard transform via string manipulation with regex:

```auto
foreach (string item : find($in.0.Document_XHTML,'<DIV class="details">(.*?)</DIV>')

```

However, this didn’t return the full outer DIV if there were any nested DIV tags within it.

Thanks

---

<div class="post-metadata">

**Author:** ![imriskal](https://avatars.discourse-cdn.com/v4/letter/i/b38774/32.png) [@imriskal](https://forum.cloverdx.com/u/imriskal)\
**Post date:** [August 19, 2013, 1:43pm UTC](https://forum.cloverdx.com/t/return-raw-xml-subset-string-from-an-xpath-query/1256/2 "2013-08-19T13:43:24Z")

</div>

Hello chathaway,

If I understand right, the described functionality is available in XMLExtract component since CloverETL version 3.4.0, see [https://bug.javlin.eu/browse/CL-2118](https://bug.javlin.eu/browse/CL-2118)

You can extract the whole XML subtree this way and then filter the result using a regexp to have only the DIVs with the desired class.

Best regards,
