XML内容如下:
<PRPM_IN401030UV01 xmlns=""urn:hl7-org:v3"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" ITSVersion=""XML_1.0"" xsi:schemaLocation=""urn:hl7-org:v3 ../multicacheschemas/PRPM_IN401030UV01.xsd"">
<receiver typeCode=""RCV"">
</receiver>
<sender typeCode=""SND"">
</sender>
</PRPM_IN401030UV01>
解析代码如下:
byte[] data = Encoding.UTF8.GetBytes(msg);
System.IO.MemoryStream ms = new System.IO.MemoryStream(data);
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
try
{
xmlDoc.Load(ms);
}
catch (Exception ex)
{
throw new Tsxd.ExceptionProcessor.ExtensibleException("解析返回结果错误:" + ex.Message);
}
System.Xml.XPath.XPathNavigator xpnRoot = xmlDoc.CreateNavigator();
XPathNavigator xpnBSXml = xpnRoot.SelectSingleNode("PRPM_IN401030UV01");
解析时xpnRoot为null,因为XML中有自定义的命名空间,需要用以下方式解析:
byte[] data = Encoding.UTF8.GetBytes(msg);
System.IO.MemoryStream ms = new System.IO.MemoryStream(data);
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
try
{
xmlDoc.Load(ms);
}
catch (Exception ex)
{
throw new Tsxd.ExceptionProcessor.ExtensibleException("解析返回结果错误:" + ex.Message);
}
XmlNamespaceManager xmlnsm = new XmlNamespaceManager(xmlDoc.NameTable);
xmlnsm.AddNamespace("ns", "urn:hl7-org:v3");
XmlNode ret = xmlDoc.SelectSingleNode("/ns:PRPM_IN401030UV01/ns:id", xmlnsm);
ret.InnerText即为id节点的值。