0

I am able to read xml using XmlReader, but not able to read xml's CDATA portion.

How to read it ?

Below is my code

private void ParseDataValueNode(XmlReader CmdNode, Message Msg)
        {
            int DataValueNodeCount = 0;
            while (CmdNode.Read())
            {
                if (CmdNode.Name.Equals("DataValue") && CmdNode.NodeType == XmlNodeType.Element)
                {
                    DataValueNodeCount++;
                    ParseDataValueNode(CmdNode, Msg, DataValueNodeCount, true);
                }
            }
        }

XML

  <Response Id="2">
    <Information>
      <![CDATA[ <DataValue Name="abc" Value="dddd"/> <DataValue Name="ccc" Value="ffff"/> <DataValue Name="ddd" Value="dfdf"/> ]]>
    </Information>
  </Response>

If xml doesn't contain CDATA then it works perfectly fine, however in case CDATA it doesn't read elements under CDATA

1
  • 1
    Everything inside CDATA is a single text() node. You need to start a new reader for that DocumentFragment Commented Dec 14, 2015 at 7:44

1 Answer 1

2

The data inside the CDATA section is treated as plain text. You need to load it's contents into the new DOMDocument. You can recognize the CDATA using this code:

if (CmdNode.NodeType == XmlNodeType.CDATA)
Sign up to request clarification or add additional context in comments.

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.