Skip to main content
mariaw
October 6, 2023
Question

How to use torecord() to convert XML with nested tags to a CDT

  • October 6, 2023
  • 5 replies
  • 0 views

I would like to convert the following XML to a CDT. I have no problem capturing the values in Key, LastModified, and Size using torecord(). However, I do not know how to create a field in my CDT to capture DisplayName using torecord() since it is nested in Owner. Please let me the best way to get the data in this XML.

<Result>
<Key>Mock_Doc.pdf</Key>
<LastModified>2023-10-06T02:19:06.000Z</LastModified>
<Size>38864</Size>
<Owner>
<DisplayName>Tracy</DisplayName>
</Owner>
</Result>

    5 replies

    stefanhelzle0001
    Brainy
    October 6, 2023

    Did you consider to fetch the values from the XML using xPath? This way you are super flexible and do not have to create a CDT that exactly matches the XML.

    mariaw
    mariawAuthor
    October 6, 2023

    Thanks for the reply. Yes, xpathsnippet() and extract() both give me the data I want. However, I am trying to avoid those extra steps. I was wondering if there was a way to set up the CDT so I can just use torecord() to get all the data points at once, including the data in the nested tags.

    stefanhelzle0001
    Brainy
    October 6, 2023

    To satisfy your curiosity, yes, simple and easy. Just create a nested CDT.

    mariaw
    mariawAuthor
    October 6, 2023

    I ended up using xml-parser and fromjson. It returned all the values nicely.