Selecting a node with child and parent condition.

O

okaissi79

<DeliverySchedule>
<Header>
<DistributorCode>MC</DistributorCode>
<TransmissionDate>2007-01-02</TransmissionDate>
<TransmissionTime>14:02:00.000</TransmissionTime>
</Header>
<Detail>
<StoreDelivery>
<SiteNum>001507</SiteNum>
<DSchedule>
<Order>
<Date>2007-09-02</Date>
<Time>08:02:01.000</Time>
</Order>
<Delivery>
<Date>2007-09-03</Date>
<Time>06:12:02.000</Time>
</Delivery>
</DSchedule>
<DSchedule>
<Order>
<Date>2007-09-04</Date>
<Time>08:02:03.000</Time>
</Order>
<Delivery>
<Date>2007-09-05</Date>
<Time>06:12:04.000</Time>
</Delivery>
</DSchedule>
</StoreDelivery>
<StoreDelivery>
<SiteNum>001510</SiteNum>
<DSchedule>
<Order>
<Date>2007-09-02</Date>
<Time>08:02:05.000</Time>
</Order>
<Delivery>
<Date>2007-09-03</Date>
<Time>06:12:06.000</Time>
</Delivery>
</DSchedule>
<DSchedule>
<Order>
<Date>2007-09-08</Date>
<Time>08:02:07.000</Time>
</Order>
<Delivery>
<Date>2007-09-09</Date>
<Time>06:12:08.000</Time>
</Delivery>
</DSchedule>
</StoreDelivery>
</Detail>
<Count>4</Count>
</DeliverySchedule>


I need to query the "Order" field or child where the field "Date"
inside it is equal for example "2007-09-02" and its parent "SiteNum" =
001507. Can I do that?

This will really help me a lot, thank you
 
J

Joe Kesselman

<DeliverySchedule>
<Header>
<DistributorCode>MC</DistributorCode>
<TransmissionDate>2007-01-02</TransmissionDate>
<TransmissionTime>14:02:00.000</TransmissionTime>
</Header>
<Detail>
<StoreDelivery>
<SiteNum>001507</SiteNum>
<DSchedule>
<Order>
<Date>2007-09-02</Date>
<Time>08:02:01.000</Time>
</Order>
<Delivery>
<Date>2007-09-03</Date>
<Time>06:12:02.000</Time>
</Delivery>
</DSchedule>
<DSchedule>
<Order>
<Date>2007-09-04</Date>
<Time>08:02:03.000</Time>
</Order>
<Delivery>
<Date>2007-09-05</Date>
<Time>06:12:04.000</Time>
</Delivery>
</DSchedule>
</StoreDelivery>
<StoreDelivery>
<SiteNum>001510</SiteNum>
<DSchedule>
<Order>
<Date>2007-09-02</Date>
<Time>08:02:05.000</Time>
</Order>
<Delivery>
<Date>2007-09-03</Date>
<Time>06:12:06.000</Time>
</Delivery>
</DSchedule>
<DSchedule>
<Order>
<Date>2007-09-08</Date>
<Time>08:02:07.000</Time>
</Order>
<Delivery>
<Date>2007-09-09</Date>
<Time>06:12:08.000</Time>
</Delivery>
</DSchedule>
</StoreDelivery>
</Detail>
<Count>4</Count>
</DeliverySchedule>


I need to query the "Order" field or child where the field "Date"
inside it is equal for example "2007-09-02" and its parent "SiteNum" =
001507. Can I do that?

The simple answer is "yes".

The longer answer is: Using which query language, and starting from
where in the document? Assuming XPath and a global search (which will
usually not be most efficient solution), one of many ways to express
this would be

//Order[Date='2007-09-02' and ../../Sitenum='001507']

See any good XPath tutorial to understand why this works, and what the
alternatives might be.

If you want to use another query language, see tutorials for that
language instead, of course.
 
J

Joe Kesselman

Typo, of course -- SiteNum, not Sitenum. But you get the idea. Or, if
not, you need to do the recommended homework.
 
K

kaissi

Typo, of course -- SiteNum, not Sitenum. But you get the idea. Or, if
not, you need to do the recommended homework.

Thank you
It worked. Exactly what I wanted.

I owe you one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top