Discussion:
How to use MSXML 4.0 to Select specific nodes
(too old to reply)
malhenry
2006-05-11 17:59:02 UTC
Permalink
Given the xml file below, I need to select 2 "incidents" based on the
following criteria.

City=TO
Active=1
Incident="Closed collision" or "Collision"
OR
Incident contains "Construct"
OR
any other incident

This seems more like a db query to me, rather than xml processing.
Is there a way for me to write code in MSXML to select the incidents I need
according to the above criteria?
It is unfortunate that the city node is NOT inside the incident node. This
is what the data vendor sends me.

Thanks.

<?xml version="1.0" encoding="ISO-8859-1" ?>
- <Tra>
<date>06-05-11</date>
<time>09:10:46</time>
<city>TO</city>
<sector>CE</sector>
- <incident>
<active>1</active>
<location>east of</location>
<route>Coxwell</route>
<incident>Construction</incident>
<lane>Right lane</lane>
</incident>
<city>TO</city>
<sector>NC</sector>
- <incident>
<active>1</active>
<location>at</location>
<route>407</route>
<incident>Broken watermain</incident>
<lane />
</incident>
<city>TO</city>
<sector>CC</sector>
- <incident>
<active>1</active>
<location>east of</location>
<route>Bathurst</route>
<incident>Closed repairs</incident>
<lane>All Lanes</lane>
</incident>
<city>TO</city>
<sector>NW</sector>
- <incident>
<active>1</active>
<location>at</location>
<route>Jane</route>
<incident>Closed repairs</incident>
<lane>All Lanes</lane>
</incident>
<city>TO</city>
<sector>CC</sector>
- <incident>
<active>1</active>
<location>between</location>
<route>Keele</route>
<incident>Construction</incident>
<lane>Right lane</lane>
</incident>
<city>TO</city>
<sector>CE</sector>
- <incident>
<active>0</active>
<location>approach</location>
<route>Whites Rd</route>
<incident>Collision</incident>
<lane>Left lane</lane>
</incident>
</Tra>
Martin Honnen
2006-05-12 12:10:07 UTC
Permalink
Post by malhenry
Given the xml file below, I need to select 2 "incidents" based on the
following criteria.
City=TO
Active=1
Incident="Closed collision" or "Collision"
OR
Incident contains "Construct"
It is not quite clear how city and incident are related as they do not
have a common parent. I have assumed that the prececing first city
sibling relates to the incident. Here is an example XPath expression

/Tra/incident[preceding-sibling::city[1] = 'TO'][active = '1' and
(incident = 'Closed collision' or incident = 'Collision' or
contains(incident, 'Construct'))]

that you can use within XSLT or pass to the selectNodes method that
MSXML exposes for XPath queries.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
malhenry
2006-05-12 13:31:02 UTC
Permalink
I will try your suggestion. Each incident occurs in a sector of a city. I
do not know why the vendor did not put the sector and city nodes as children
of the incident node. It would have made the file easier to parse.

Thanks.
Post by Martin Honnen
Post by malhenry
Given the xml file below, I need to select 2 "incidents" based on the
following criteria.
City=TO
Active=1
Incident="Closed collision" or "Collision"
OR
Incident contains "Construct"
It is not quite clear how city and incident are related as they do not
have a common parent. I have assumed that the prececing first city
sibling relates to the incident. Here is an example XPath expression
/Tra/incident[preceding-sibling::city[1] = 'TO'][active = '1' and
(incident = 'Closed collision' or incident = 'Collision' or
contains(incident, 'Construct'))]
that you can use within XSLT or pass to the selectNodes method that
MSXML exposes for XPath queries.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Loading...