如下的xml代码:
|
<?xml version="1.0" encoding="utf-16" ?> <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2"> <Title>Events</Title> <FrameType>None</FrameType> <Description>Use the Events list to post information about meetings, deadlines, and other events related to this area.</Description> <IsIncluded>true</IsIncluded> <ZoneID>MiddleTopZone</ZoneID> <PartOrder>1</PartOrder> <FrameState>Normal</FrameState> <Height /> <Width /> <AllowRemove>true</AllowRemove> <AllowZoneChange>true</AllowZoneChange> <AllowMinimize>true</AllowMinimize> <AllowConnect>true</AllowConnect> <AllowEdit>true</AllowEdit> <AllowHide>true</AllowHide> <IsVisible>true</IsVisible> <DetailLink>/Lists/Events</DetailLink> <HelpLink /> <HelpMode>Modeless</HelpMode> <Dir>Default</Dir> <PartImageSmall /> </WebPart> |
想获取ZoneID里面的值,用如下的代码:
|
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(strResult);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("WebPart", "http://schemas.microsoft.com/WebPart/v2");
XmlNode webPartZoneNode = xmlDoc.DocumentElement.SelectSingleNode("WebPart:ZoneID", nsmgr); |
其中这两句是精髓:
nsmgr.AddNamespace("WebPart", "http://schemas.microsoft.com/WebPart/v2");
xmlDoc.DocumentElement.SelectSingleNode("WebPart:ZoneID", nsmgr);