![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | parsing xml I am parsing an xml file but looking for advice on how to better approach. How do I go about enumerating through the VLAN tags since they have a unqiue number for each one. I am enumerating each Device attribute. As of right now I am using a for loop that starts at 1 and goes up to 3. I would like to just enumerate the tags instead of using a counter. Code snippet - I left out the intialtialization of loading up xml. Counter = 0 For h = 1 To 3 Set NetworknodeList = XML.selectNodes("//MyNetwork/Networks/VLAN" & h & "00/Network") For i = 0 To NetworknodeList.length -1 sDeviceId=NetworknodeList(i).Attributes.getNamedItem("DeviceId").value sBeginRange=NetworknodeList(i).Attributes.getNamedItem("BeginRange").value sEndRange=NetworknodeList(i).Attributes.getNamedItem("EndRange").value For j = sBeginRange To sEndRange WScript.Echo sDeviceId & " " & ip & Counter Counter= Counter + 1 Next Next Next ----------SAMPLE XML FILE--------- <MyNetwork> <Networks> <VLAN100> <Network DeviceId="Router" BeginRange="1" EndRange="1"/> </VLAN100> <VLAN200> <Network DeviceId="Router" BeginRange="1" EndRange="1"/> </VLAN200> <VLAN300> <Network DeviceId="Router" BeginRange="1" EndRange="1"/> </VLAN300> </MyNetwork> |
My System Specs![]() |
| | #2 (permalink) |
| | Re: parsing xml That's why it's a poorly designed schema, having a VLAN element with an attribute signifying the number would be better. One approach would be to use: /MyNetwork/Networks/*/Network. You don't need the expensive // operator at the start if MyNetwork is the document element. Alternatively: /MyNetwork/Networks/*[starts-with(local-name(), 'VLAN')]/Network -- Joe Fawcett (MVP - XML) http://joe.fawcett.name "Big D" <BigDaddy@xxxxxx> wrote in message news:Oexqspj9IHA.4092@xxxxxx Quote: > I am parsing an xml file but looking for advice on how to better approach. > > How do I go about enumerating through the VLAN tags since they have a > unqiue number for each one. I am enumerating each Device attribute. > > As of right now I am using a for loop that starts at 1 and goes up to 3. I > would like to just enumerate the tags instead of using a counter. > > Code snippet - I left out the intialtialization of loading up xml. > > Counter = 0 > For h = 1 To 3 > Set NetworknodeList = XML.selectNodes("//MyNetwork/Networks/VLAN" & h & > "00/Network") > For i = 0 To NetworknodeList.length -1 > sDeviceId=NetworknodeList(i).Attributes.getNamedItem("DeviceId").value > > sBeginRange=NetworknodeList(i).Attributes.getNamedItem("BeginRange").value > sEndRange=NetworknodeList(i).Attributes.getNamedItem("EndRange").value > > For j = sBeginRange To sEndRange > WScript.Echo sDeviceId & " " & ip & Counter > Counter= Counter + 1 > Next > Next > Next > > > ----------SAMPLE XML FILE--------- > <MyNetwork> > > <Networks> > > <VLAN100> > > <Network DeviceId="Router" BeginRange="1" EndRange="1"/> > > </VLAN100> > > <VLAN200> > > <Network DeviceId="Router" BeginRange="1" EndRange="1"/> > > </VLAN200> > > <VLAN300> > > <Network DeviceId="Router" BeginRange="1" EndRange="1"/> > > </VLAN300> > > </MyNetwork> > > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: parsing xml I implemented the following /MyNetwork/Networks/*/Network per your direction and it worked. For best practices should I remove the numbers following the VLAN and just have VLAN tags. I need to idnetify each vlan with a number. Where should I put the number? I updated example below but looking for best approach. Thanks! ----------UPDATED SAMPLE XML FILE--------- <MyNetwork> <Networks> <VLAN> <vlanID>1</vlanID> <Network DeviceId="Router" BeginRange="1" EndRange="1"/> </VLAN> <VLAN> <vlanID>2</vlanID> <Network DeviceId="Router" BeginRange="1" EndRange="1"/> </VLAN> <VLAN> <vlanID>3</vlanID> <Network DeviceId="Router" BeginRange="1" EndRange="1"/> </VLAN> </MyNetwork> "Joe Fawcett" <joefawcett@xxxxxx> wrote in message news:upJJg2k9IHA.4536@xxxxxx Quote: > That's why it's a poorly designed schema, having a VLAN element with an > attribute signifying the number would be better. > One approach would be to use: /MyNetwork/Networks/*/Network. > You don't need the expensive // operator at the start if MyNetwork is the > document element. > Alternatively: /MyNetwork/Networks/*[starts-with(local-name(), > 'VLAN')]/Network > > -- > > Joe Fawcett (MVP - XML) > http://joe.fawcett.name > "Big D" <BigDaddy@xxxxxx> wrote in message > news:Oexqspj9IHA.4092@xxxxxx Quote: >> I am parsing an xml file but looking for advice on how to better >> approach. >> >> How do I go about enumerating through the VLAN tags since they have a >> unqiue number for each one. I am enumerating each Device attribute. >> >> As of right now I am using a for loop that starts at 1 and goes up to 3. >> I would like to just enumerate the tags instead of using a counter. >> >> Code snippet - I left out the intialtialization of loading up xml. >> >> Counter = 0 >> For h = 1 To 3 >> Set NetworknodeList = XML.selectNodes("//MyNetwork/Networks/VLAN" & h & >> "00/Network") >> For i = 0 To NetworknodeList.length -1 >> sDeviceId=NetworknodeList(i).Attributes.getNamedItem("DeviceId").value >> >> sBeginRange=NetworknodeList(i).Attributes.getNamedItem("BeginRange").value >> sEndRange=NetworknodeList(i).Attributes.getNamedItem("EndRange").value >> >> For j = sBeginRange To sEndRange >> WScript.Echo sDeviceId & " " & ip & Counter >> Counter= Counter + 1 >> Next >> Next >> Next >> >> >> ----------SAMPLE XML FILE--------- >> <MyNetwork> >> >> <Networks> >> >> <VLAN100> >> >> <Network DeviceId="Router" BeginRange="1" EndRange="1"/> >> >> </VLAN100> >> >> <VLAN200> >> >> <Network DeviceId="Router" BeginRange="1" EndRange="1"/> >> >> </VLAN200> >> >> <VLAN300> >> >> <Network DeviceId="Router" BeginRange="1" EndRange="1"/> >> >> </VLAN300> >> >> </MyNetwork> >> >> |
My System Specs![]() |
| | #4 (permalink) |
| | Re: parsing xml "Big D" wrote: Quote: > For best practices should I remove the numbers following the VLAN and just > have VLAN tags. I need to idnetify each vlan with a number. Where should I > put the number? I updated example below but looking for best approach. Quote: > ----------UPDATED SAMPLE XML FILE--------- > <MyNetwork> > <Networks> > <VLAN> > <vlanID>1</vlanID> > <Network DeviceId="Router" BeginRange="1" EndRange="1"/> > </VLAN> > <VLAN> > <vlanID>2</vlanID> > <Network DeviceId="Router" BeginRange="1" EndRange="1"/> > </VLAN> > <VLAN> > <vlanID>3</vlanID> > <Network DeviceId="Router" BeginRange="1" EndRange="1"/> > </VLAN> > </MyNetwork> its id, you'd have to find the vlanID node first and then go back up a level to get to the VLAN, per se. So why not simply us <VLAN id="1">....</VLAN> <VLAN id="2">....</VLAN> etc. ??? Now you can do an XPath query to get any particular VLAN quite easily. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Data parsing - .NET | PowerShell | |||
| xml parsing issue | VB Script | |||
| Parsing Web content | PowerShell | |||
| Command parsing | PowerShell | |||