Board index » delphi » Parsing Child Nodes

Parsing Child Nodes


2005-12-09 12:11:02 AM
delphi67
Having just started using XML, I have an XML file with the following
structure:
<Colloection>
<Section>
<Line></Line>
<Line></Line>
<Line></Line>
<Summary></Summary>
</Section>
</Section>.....
</Section>
</Collection>
There are an unknown number of sections, and each section has an
unknown no of lines, and may or may not have a summary.
Giving a Section number, how can I determine how many Line Nodes it
has, and whether it has a Summary Node?
Nirmal
 
 

Re:Parsing Child Nodes

Nirmal Singh writes:
Quote
Having just started using XML, I have an XML file with the following
structure:

<Colloection>
<Section>
<Line></Line>
<Line></Line>
<Line></Line>
<Summary></Summary>
</Section>
</Section>.....

</Section>
</Collection>

There are an unknown number of sections, and each section has an
unknown no of lines, and may or may not have a summary.

Giving a Section number, how can I determine how many Line Nodes it
has, and whether it has a Summary Node?
Assuming you have the sequence number of the desired Section element
in the variable $n:
The XPath expression "count(Section[position()=$n]/Line)" will return
the number of Line elements in the $nth Section.
The Boolean XPath expression "Section[position()=$n]/Summary" will
evaluate to .true. if a Summary element is present.
///Peter
--
XML FAQ: xml.silmaril.ie/
 

Re:Parsing Child Nodes

On Thu, 08 Dec 2005 22:04:47 +0000, Peter Flynn <XXXX@XXXXX.COM>
writes:
Quote
Assuming you have the sequence number of the desired Section element
in the variable $n:

The XPath expression "count(Section[position()=$n]/Line)" will return
the number of Line elements in the $nth Section.

The Boolean XPath expression "Section[position()=$n]/Summary" will
evaluate to .true. if a Summary element is present.

Peter, what is XPath? I am using TXMLDocument with Delphi 7 professional.
Nirmal
 

Re:Parsing Child Nodes

XPath is an XLS extension supported by the default MS XML Parser that allows
scripting of an XML source.
That being said you can also try my freeware XML parser out as it gives you
fast easy access to the XML structure w/o a lot of overhead. Of course it
also doesn't have some of the nice features that other XML parsers have (XLS
Scripting support for example).
Download at: eonclash.com/ViewProduct.php
In it you simply do:
XML.LoadFromFile('MyFile.xml');
XML.Root.NamedItem['SomeName'].SubItems[5].Count
Where NamedItem can walk down using "Name/Name" relations and SubItems gives
you indexed access to all sub nodes of any given node. Count of course
returns the count of the nodes that the parent contains.
- Jeremy
"Nirmal Singh" <XXXX@XXXXX.COM>writes
Quote
On Thu, 08 Dec 2005 22:04:47 +0000, Peter Flynn <XXXX@XXXXX.COM>
writes:

>Assuming you have the sequence number of the desired Section element
>in the variable $n:
>
>The XPath expression "count(Section[position()=$n]/Line)" will return
>the number of Line elements in the $nth Section.
>
>The Boolean XPath expression "Section[position()=$n]/Summary" will
>evaluate to .true. if a Summary element is present.
>

Peter, what is XPath? I am using TXMLDocument with Delphi 7 professional.

Nirmal
 

Re:Parsing Child Nodes

On Mon, 12 Dec 2005 09:10:17 -0600, "Jeremy Darling"
<XXXX@XXXXX.COM>writes:
Quote
XPath is an XLS extension supported by the default MS XML Parser that allows
scripting of an XML source.

That being said you can also try my freeware XML parser out as it gives you
fast easy access to the XML structure w/o a lot of overhead. Of course it
also doesn't have some of the nice features that other XML parsers have (XLS
Scripting support for example).

Download at: eonclash.com/ViewProduct.php

In it you simply do:
XML.LoadFromFile('MyFile.xml');
XML.Root.NamedItem['SomeName'].SubItems[5].Count

Where NamedItem can walk down using "Name/Name" relations and SubItems gives
you indexed access to all sub nodes of any given node. Count of course
returns the count of the nodes that the parent contains.

Jeremy
I've downloaded your parser. I will let you know how I get on with it.
Thanks.
Nirmal