3

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?

0

4 Answers 4

1

You need to get CDATA node, load it to separate XmlDocument, and call XPath query again.

Sign up to request clarification or add additional context in comments.

Comments

1

So actually I just changed the outer body tag to bodyHtml tag instead.... and then use:

/mailAndMessageSettings/mail/bodyHtml

Comments

0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.