# How to capture \[element contents\] in XML Extract or else?

**URL:** <https://forum.cloverdx.com/t/how-to-capture-element-contents-in-xml-extract-or-else/1032>\
**Category:** CloverDX Platform\
**Created:** [March 20, 2012, 12:00am UTC](https://forum.cloverdx.com/t/how-to-capture-element-contents-in-xml-extract-or-else/1032 "2012-03-20T00:00:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![evanchen](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@evanchen](https://forum.cloverdx.com/u/evanchen)\
**Post date:** [March 20, 2012, 12:00am UTC](https://forum.cloverdx.com/t/how-to-capture-element-contents-in-xml-extract-or-else/1032/1 "2012-03-20T00:00:00Z")

</div>

Hi Master,

With “XML Extract” how can I treat the [element contents] under element in ex1 as the same as in ex2?

ex1:  
  
  
DEFINE1  
  
  
DEFINE2

ex2:  
  
  
DEFINE1  
  
  
DEFINE2

In another word, how could I get the structured data once transforming ex1 into Clover metadata as below?

**Key**  **Attribute**  
alpha DEFINE1  
beta DEFINE2

I tried to map that [element contents] to a Clover Field in “Mapping” tab of “XML Extract”, but the values in the result are null, I assume that in general all the elements included in \<\> need be predefined to make them identified. Is there any possibility to escape this criterion at such XML level?

I will appreciate any of your ideas or workaround solutions.

Thanks,

---

<div class="post-metadata">

**Author:** ![David\_Hlidek](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@David\_Hlidek](https://forum.cloverdx.com/u/David_Hlidek)\
**Post date:** [March 20, 2012, 11:50am UTC](https://forum.cloverdx.com/t/how-to-capture-element-contents-in-xml-extract-or-else/1032/2 "2012-03-20T11:50:01Z")

</div>

Hi evanchen,

what you want is directly not possible. I would recommend to do some kind of xml text preprocessing. You can:

1] remove unwanted elements “” and “” (eg. by CTL2 function ‘replace(orig, “”, “”)’)  
2] somehow escape XML control characters of unwanted elements (eg. by CTL2 function ‘replace(orig, “”, “\<definition\>”)’)

Then it will be readable by XmlExtract as you want.

---

<div class="post-metadata">

**Author:** ![evanchen](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@evanchen](https://forum.cloverdx.com/u/evanchen)\
**Post date:** [March 20, 2012, 1:32pm UTC](https://forum.cloverdx.com/t/how-to-capture-element-contents-in-xml-extract-or-else/1032/3 "2012-03-20T13:32:43Z")

</div>

Hi Jaroslav,

Thanks again for you support, actually my case is more complicated than I mentioned in the previous example. my current case is as below:

ex:  
  
  
DEFINE1  
ATTRIBUTE1  
METRIC1  
  
  
DEFINE2  
ATTRIBUTE2  
METRIC3

and I need to keep those blue values entirely in the output port, do you know if other component such as XSLTransformer and XMLXPathReader can work for this request? if so, any examples?

---

<div class="post-metadata">

**Author:** ![David\_Hlidek](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@David\_Hlidek](https://forum.cloverdx.com/u/David_Hlidek)\
**Post date:** [March 21, 2012, 2:14pm UTC](https://forum.cloverdx.com/t/how-to-capture-element-contents-in-xml-extract-or-else/1032/4 "2012-03-21T14:14:25Z")

</div>

Hi evanchen,

Please take a look on attached graph, try to debug in and observe values on edges.

- [test\_xml\_escape.grf](https://cdn.cloverdx.com/forum/15157%5F2d0a85db295d7eebfed8dc4013a373bf/test%5Fxml%5Fescape.grf)

---

<div class="post-metadata">

**Author:** ![evanchen](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@evanchen](https://forum.cloverdx.com/u/evanchen)\
**Post date:** [March 22, 2012, 3:08am UTC](https://forum.cloverdx.com/t/how-to-capture-element-contents-in-xml-extract-or-else/1032/5 "2012-03-22T03:08:35Z")

</div>

Hello Jaroslav,

Thanks for your example!

I had thought out the similar approach, but your CTL2 code seems more elegant. 😃
