Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse XML FileIn ASP

Status
Not open for further replies.

nidgep

Programmer
Sep 4, 2001
80
GB
Hi

I have an xml file that has various nodes within each section.
What I would like to be able to do using xpath queries is to select all <item> nodes that dont have a specific child node of <broaderItem>.

Example snippet:
Code:
[COLOR=blue]
<Item Id="1" ConceptId="1" Obsolete="false" AddedInVersion="2.00" LastUpdatedInVersion="2.00" AToZ="false" Category="true" Preferred="true">
    <Name>Adult care services</Name>
    <ScopeNotes>All matters relating to the help and support of adult individuals.</ScopeNotes>
  </Item>
  <Item Id="2" ConceptId="2" Obsolete="false" AddedInVersion="2.00" LastUpdatedInVersion="2.00" AToZ="false" Category="true" Preferred="true">
    <Name>Carers</Name>
    <ScopeNotes>Information relating to carers.  Carer files would typically be organised by name and some form of identifier.</ScopeNotes>
    <BroaderItem Id="1" ConceptId="1" Default="true">Adult care services</BroaderItem>
  </Item>[/color]
SO in the example above I would only want to have the first node returned but not the second as it contains the <BroaderItem> tag.

Any help would be greatly appreciated.

thanks in advance

nidgep
 
[tt] .selectnodes("//Item[not(./BroaderItem)]")[/tt]
 
thanks tsuji for the quick response.

Assuming that the <root> node is named <ControlledList> then the solution would then become.
Code:
[COLOR=blue]
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
var matchedNodes;
xmlDoc.async = false;
xmlDoc.load("lgcs.xml"); 
[COLOR=green]//select those nodes that do not have a BroaderItem child[/color][COLOR=red]
matchedNodes = xmlDoc.selectNodes(("//ControlledList/Item[not(./BroaderItem)]");[/color][/color]

Once again thanks for your help and do you know of any good web resouces on xpath where I can find operators and such like dor use with xpath? I had looked at w3schools but they did not list the [not] operator.

regards

nidgep
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top