Need to parse the xml string

I need to parse an xml string (.NET, C #), which, unfortunately, is not very well formed. xml stream i get

<fOpen>true</fOpen> <ixBugParent>0</ixBugParent> <sLatestTextSummary></sLatestTextSummary> <sProject>Vantive</sProject> <ixArea>9</ixArea> 

I tried using an xml reader, but it crashed because it thinks, and rightfully, there are two node elements when it tries to parse

Is there something I can do with this? I cannot change the XML because I have no control over the code that sends the XML back.

Any help would be appreciated.

Thanks and Regards

Gagan Janjua

+4
source share
2 answers

I think you can use XmlParserContext in one of the XmlTextReader overloads to indicate that the node type is XmlNodeType.Element , similar to this example from MSDN ( http://msdn.microsoft.com/en-us/library/cakk7ha0.aspx ):

 XmlTextReader tr = new XmlTextReader("<element1> abc </element1> <element2> qrt </element2> <?pi asldfjsd ?> <!-- comment -->", XmlNodeType.Element, null); while(tr.Read()) { Console.WriteLine("NodeType: {0} NodeName: {1}", tr.NodeType, tr.Name); } 
+7
source

What you get back is a well-formed XML fragment, but as you pointed out, it is not a well-formed XML document. Can you

  • wrap top-level item around returned items? or
  • refers to the returned XML fragment as an external object from the shell XML document and passes the shell document to the XML reader?
+1
source

All Articles