How can I access data (CDATA) in this xml node using Xpath?

I have the following XML:

<?xml version="1.0" encoding="UTF-9" ?>
<mailAndMessageSettings>
    <settings>
        <add key="Url" value=""/>
        <add key="UserName" value=""/>
        <add key="Password" value=""/>
    </settings>
    <mail>
        <subject>
            Mp3 Submission
        </subject>
        <body>
            <![CDATA[
                <meta http-equiv="Content-Type" content="text/html; charset="utf-8""/>
                <head></head>

                <body>
                <p>Hi,</p>

                <p>Please find the attached mp3... :-)</p>

                <p><a href="mymp3.mp33">here</a></p>

                <p>Regards,</br>
                Pete</p>

                </body>
                </html> 
            ]]>
        </body>
    </mail>    
</mailAndMessageSettings>

And I want to use XPath:

/mailAndMessageSettings/mail/body

However, when I use it, it selects everything from the first body tag (correctly) into the body tag inside the html, and not the body tag in the XML document ...

How can I select all CDATA inside an XML body without a CDATA tag?

+3
source share
4 answers

So in fact, I just replaced the outer body tag with the bodyHtml tag instead ... and then used:

/mailAndMessageSettings/mail/bodyHtml
+1
source

You need to get the CDATA node, load it to split the XmlDocument, and call the XPath request again.

+1
source

CDATA , , .

If you don't check this out and you don't seem to declare it as HTML (which would limit the presence of double-body tags), I'm not sure why you need an ad CDATA. If this is because it is dynamically generated and you don't know what can be created in lines, you should wrap the text in dynamically generated html in CDATAinstead.

0
source

Use /mailAndMessageSettings/mail/body/text().

0
source

All Articles