类似这样的XML怎么解开才是最好的方案?
这是厂商反馈回来的XML格式,他们可能使用的是偏Linux等系统,而且是自己定义的。
怎样揭开这个XML才是最优方案?
谢谢!
<?xml version= '1.0 ' encoding= 'UTF-8 '? >
<UranusMsg xmlns="http://www.vivotek.com/Surveillance/ST7501" >
<Header >
<Fixed >
<Type >Res </Type >
<CmdName >ClientHello </CmdName >
<SID >4AEF004F8E01000009A800000F10080046648CF4 </SID >
<Priority >3 </Priority >
<Flags >1 </Flags >
</Fixed >
<Variant >
<Size >0000000485 </Size >
<Target > </Target >
<Return > </Return >
</Variant >
</Header >
<Body >
<UranusRes xmlns="http://www.vivotek.com/Surveillance/ST7501" >
<Code >0 </Code >
<Info >SecurityPolicy </Info >
<SecurityPolicy >
<Version >1.0 </Version >
<AuthList >
<Auth >
<Method >STSimple </Method >
<Param >E2358F2403B8E6D5A60F5BD632B3CFC15F0C099BDEA8BEC0C18235AC8E6247DC </Param >
</Auth >
</AuthList >
<MyName >S_{12345678-9012-3456-7890-123456789012} </MyName >
<MyRefName >S_TestServer </MyRefName >
<YourName >U_6 </YourName >
</SecurityPolicy >
</UranusRes >
</Body >
</UranusMsg >
------解决方案--------------------怎么不是标准的xml了?别被CSDN加几个多余的空格给蒙蔽了,参考如下代码:
C# code
XmlDocument vXmlDocument = new XmlDocument();
vXmlDocument.Load(@"c:\temp\temp.xml");
XmlNode vRoot = vXmlDocument.DocumentElement;
XmlNamespaceManager vXmlNamespaceManager =
new XmlNamespaceManager(vXmlDocument.NameTable);
vXmlNamespaceManager.AddNamespace("bk",
"http://www.vivotek.com/Surveillance/ST7501");
XmlNode vType = vXmlDocument.SelectSingleNode(
"/bk:UranusMsg/bk:Header/bk:Fixed/bk:Type",
vXmlNamespaceManager);
if (vType != null) Console.WriteLine("Type.Text={0}", vType.InnerText);
XmlNode vCmdName = vXmlDocument.SelectSingleNode(
"/bk:UranusMsg/bk:Header/bk:Fixed/bk:CmdName",
vXmlNamespaceManager);
if (vCmdName != null) Console.WriteLine("CmdName.Text={0}", vCmdName.InnerText);