Home > Net >  Ask a question, about the incomplete XML document parsing and assembly
Ask a question, about the incomplete XML document parsing and assembly

Time:10-01

See the customer document, one of the requirements is the returned string is this format, and confusion is particularly illustrates this is a XML format:
123456 & lt;/meterID> Abcdefgh
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 death
The 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 data

CodePudding user response:

If there are rules to follow, you can use regular expressions, otherwise it's hard to say

CodePudding 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 good

XML 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 ());
  •  Tags:  
  • C#
  • Related