Finding Sibling Node By Name

crunmulteri

New Member
I am reading the applicationHost.xml.config file for IIS. I am getting the Virtual Directories of EACH Site in Sites and then getting the information I need from that point. Information like the physical path and path. Then I need to get the the Bindings. I cannot figure out how to effectively get to the "Bindings" element node, when I have TWO application nodes. (An example of this is shown below) However, I CAN use "site.ParentNode.NextSibling.ChildNodes" which gets me a list of the respective bindings IF there is ONE application node.Thanks in advance for your help!My Code:\[code\]XDocument.Load(@"C:\\windows\\system32\\inetsrv\\config\\applicationHost.config");XmlNodeList siteList = XDocument.SelectNodes("/configuration/system.applicationHost/sites/site/application/virtualDirectory");foreach (XmlNode site in siteList){ XmlAttribute XmlAttributeParentParentName = (XmlAttribute)site.ParentNode.ParentNode.Attributes.GetNamedItem("name"); XmlAttribute XmlAttributePath = (XmlAttribute)site.Attributes.GetNamedItem("path"); XmlAttribute XmlAttributePhysicalPath = (XmlAttribute)site.Attributes.GetNamedItem("physicalPath"); XmlNodeList BindingList = (XmlNodeList)site.ParentNode.NextSibling.ChildNodes; string path = XmlAttributePath.Value.ToString(); string siteName = XmlAttributeParentParentName.Value.ToString(); string physicalPath = XmlAttributePhysicalPath.Value.ToString(); string firstBindingElement = BindingList[0].Attributes.GetNamedItem("bindingInformation").Value.ToString(); //do something with the variables. //rest of code is here}\[/code\]Here is an example of a Site node:\[code\]<site name="Site Name" id="20" serverAutoStart="true"> <application path="/" applicationPool="SiteAppPool"> <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\SiteName" /> </application> <application path="/store" applicationPool="SiteAppPool"> <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\SiteName\store" /> </application> <bindings> <binding protocol="http" bindingInformation="*:80:sitename.com" /> </bindings></site>\[/code\]
 
Back
Top