首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

*请教怎么解析XML中的属性的值*

2011-12-31 
*****请问如何解析XML中的属性的值******XML如下:-HJEDIxmlns http://webservices.sabre.com/sabreXML/

*****请问如何解析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);
......

热点排行