This is not a complete XML file, there is no file header, not can use LoadXml to parse, I am strange, how to resolve this format? You say it's XML, but clearly this is not XML
CodePudding user response:
You write XML header parsing o deathThe caption splice in the middle
CodePudding user response:
Supposedly the XML content is & lt; Item> The content & lt;/item> In pairs, but the above & lt; Item> . Alone after a string of dataCodePudding user response:
If there are rules to follow, you can use regular expressions, otherwise it's hard to sayCodePudding user response:
123456 & lt;/meterID> Abcdefgh
You can use regular expressions to rule out first element string..
Then you can use linq XML..
CodePudding user response:
A layer of XML node set goodXML string="& lt; MeterID> 123456 & lt;/meterID> Abcdefgh ";
String xmlHead="& lt; ? The XML version=\ \ "1.0" encoding=\ "gb2312 "?>
The StringBuilder strXml=new StringBuilder ();
StrXml. Append (xmlHead);
StrXml. Append (XML);
StrXml. Append (" & lt;/Temp>" );
XmlDocument doc=new XmlDocument ();
Doc. LoadXml (strXml. ToString ());