XPathReader是开源的XPathReader.dll中的一个核心类。该类基于XPath来获取XML文件中的节点值,解析模式是SAX。
示例代码:
SeekableReadOnlyStream vs = new SeekableReadOnlyStream(inmsg.BodyPart.GetOriginalDataStream());
XPathCollection xc = new XPathCollection();
xc.Add("//file_header/SENDER_ID");
xc.Add("//file_header/MSG_TYPE");
XPathReader xpreader = new XPathReader(new System.Xml.XmlTextReader(vs), xc);
while (xpreader.ReadUntilMatch())
{
switch (xpreader.LocalName.ToUpper())
{
case "SENDER_ID":
......
}
}