Skip to main content
mariaw
Participating Frequently
Oct 6, 2023 2:44 AM UTC
Question

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

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
    Oct 6, 2023 6:53 AM UTC

    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
    Participating Frequently
    Oct 6, 2023 11:32 AM UTC

    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
    Oct 6, 2023 1:21 PM UTC

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

    mariaw
    mariawAuthor
    Participating Frequently
    Oct 6, 2023 1:03 PM UTC

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