Selecting XML nodes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know the notation of how to select XML nodes based on an
attribute. I know that it will be something like:
root.SelectNodes ("descendant::key....")

Sample xml is
<indexdata>
<key name="buffy">
<topic name="buffy" url="buffy/buffy.htm"/>
<topic name="scooby gang" url="buffy/good_guys/scooby_gang.htm" />
</key>
</indexdata>

Basically, I want to get the url when the name = buffy or scooby gang.
I know, I have such an interesting help file. ;)

Thank you,
Susan
 
This line:
foreach(XmlNode db in x.SelectNodes("/jobs/job[@sourcedb and @destdb and
@name]"))

selects all the "job" nodes represented in this XML file:
(ONLY if they have got a valid sourcedb and destdb attribute):

<?xml version="1.0" encoding="utf-8" ?>
<jobs>
<job name="System info" sourcedb="irf0429" destdb="SystemInfo.mdb">
<table name="SystemInfo"/>
</job>
<job name="Collections vs. Maturities" sourcedb="irf0429"
destdb="CollsMaturities.mdb">
<table name="EXC_AgencyCollsMature"/>
<table name="EXC_BranchCollsMature"/>
<table name="EXC_SectionCollsMature"/>
<table name="EXC_ROMCollsMature"/>
<table name="EXC_DOMCollsMature"/>
<table name="EXC_CompanyCollsMature"/>
<table name="GRAPH_AgencyCollsMature"/>
<table name="GRAPH_BranchCollsMature"/>
<table name="GRAPH_SectionCollsMature"/>
<table name="GRAPH_ROMCollsMature"/>
<table name="GRAPH_DOMCollsMature"/>
<table name="GRAPH_CompanyCollsMature"/>
</job>
</jobs>

don't know if that's any help to you, hope so
 
I was able to get the answer from that. I just needed the @name and was able
to put in the ='Cats'. Thank you so much!!!

Patty O'Dors said:
This line:
foreach(XmlNode db in x.SelectNodes("/jobs/job[@sourcedb and @destdb and
@name]"))

selects all the "job" nodes represented in this XML file:
(ONLY if they have got a valid sourcedb and destdb attribute):

<?xml version="1.0" encoding="utf-8" ?>
<jobs>
<job name="System info" sourcedb="irf0429" destdb="SystemInfo.mdb">
<table name="SystemInfo"/>
</job>
<job name="Collections vs. Maturities" sourcedb="irf0429"
destdb="CollsMaturities.mdb">
<table name="EXC_AgencyCollsMature"/>
<table name="EXC_BranchCollsMature"/>
<table name="EXC_SectionCollsMature"/>
<table name="EXC_ROMCollsMature"/>
<table name="EXC_DOMCollsMature"/>
<table name="EXC_CompanyCollsMature"/>
<table name="GRAPH_AgencyCollsMature"/>
<table name="GRAPH_BranchCollsMature"/>
<table name="GRAPH_SectionCollsMature"/>
<table name="GRAPH_ROMCollsMature"/>
<table name="GRAPH_DOMCollsMature"/>
<table name="GRAPH_CompanyCollsMature"/>
</job>
</jobs>

don't know if that's any help to you, hope so
Susan said:
Does anyone know the notation of how to select XML nodes based on an
attribute. I know that it will be something like:
root.SelectNodes ("descendant::key....")

Sample xml is
<indexdata>
<key name="buffy">
<topic name="buffy" url="buffy/buffy.htm"/>
<topic name="scooby gang" url="buffy/good_guys/scooby_gang.htm" />
</key>
</indexdata>

Basically, I want to get the url when the name = buffy or scooby gang.
I know, I have such an interesting help file. ;)

Thank you,
Susan
 
Back
Top