日期:2014-05-19  浏览次数:20732 次

*****请问如何解析XML中的属性的值******
XML如下:
-   <HJEDI   xmlns= "http://webservices.sabre.com/sabreXML/2003/07 "   xmlns:xs= "http://www.w3.org/2001/XMLSchema "   xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance "   EchoToken= "String "   TimeStamp= "2007-05-21T02:53:07 "   Target= "Production "   Version= "2003A.TsabreXML1.0.1 "   SequenceNmbr= "1 "   PrimaryLangID= "en-us "   AltLangID= "en-us ">
    <Success   />  
-   <EDI>
-   <Path>
-   <APL>
    <OriginCityTimeZoneCode   Code= "Z8 "   />  
    <TimeZoneDifference   Code= "ABCD "   />  
    </APL>
    </Path>
    </EDI>
    </HJEDI>

请问如何得到:
Z8
ABCD

谢谢

------解决方案--------------------
添加一个namespace mananger。
定义和使用如下:
FileStream fs = new FileStream( "FilePath ", FileMode.Open, FileAccess.Read, FileShare.Read);

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(fs);

XmlElement root = xmlDoc.DocumentElement;
XmlNamespaceManager manager = new XmlNamespaceManager(xmlDoc.NameTable);
manager.AddNamespace( "DomainCodeList ",root.NamespaceURI);

XmlNodeList nodes = root.SelectNodes( "HJEDI:EDI ",manager);
......