Reputation: 29720
I have next XML:
<?xml version="1.0" encoding="UTF-8"?>
<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 an XPath:
/mailAndMessageSettings/mail/body
However when I use it, it is selecting everything from the first body tag (correct) to the body tag inside the html rather than the body tag in the XML document...
How can I select all of the CDATA inside the body XML without the CDATA tag included?
Upvotes: 3
Views: 7773
Reputation: 29720
So actually I just changed the outer body tag to bodyHtml tag instead.... and then use:
/mailAndMessageSettings/mail/bodyHtml
Upvotes: 1
Reputation: 100238
You need to get CDATA node, load it to separate XmlDocument, and call XPath query again.
Upvotes: 1
Reputation: 70487
The parser is only going to make the CDATA accessible as text, because that's what it's used for.
If you aren't validating this, and you don't appear to be declaring it as HTML (which would restrict the presence of double body tags), I'm not sure why you need the CDATA
declaration. If it's because it's dynamically generated, and you're not sure what might be generated in the strings, you should be wrapping the text in the dynamically generated html in CDATA
instead.
Upvotes: 0