Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

DOM and the order of its Nodes

Does anyone know if there is a fixed order between the different types of
DOM Nodes?
Are the manufactures of Parsers obliged to put the different Node types in a
special order?

Are DOM Element Nodes always to be before DOM Text Nodes?

In the W3 documents they place the nodes in this logical order, but I can't
find anywhere in either DOM level1 or Level2 W3 documentation that
explicitly says so. No sort functions exist in the Parser I use (Xercex for
C++), so if I can't rely 100% on them beeing in the same order I have to
sort them.

So can I when writing programs assume Element Nodes always are before Text
Nodes?

Cheers

Fredrik Svensson
[730 byte] By [Fredrik] at [2007-11-9 15:23:19]
# 1 Re: DOM and the order of its Nodes
"Fredrik" <fredrik@cimade.com> wrote:
>Does anyone know if there is a fixed order between the different types of
>DOM Nodes?
I know.

>Are the manufactures of Parsers obliged to put the different Node types
in a
>special order?
Yep. It's the same order you get when you read the XML document serially.

>Are DOM Element Nodes always to be before DOM Text Nodes?
Nope. Otherwise, the document you read in could not be the same as the document
you write out.

>In the W3 documents they place the nodes in this logical order, but I can't
>find anywhere in either DOM level1 or Level2 W3 documentation that
>explicitly says so. No sort functions exist in the Parser I use (Xercex
for
>C++), so if I can't rely 100% on them beeing in the same order I have to
>sort them.
The nodes are in the order in which they appear in the XML document.

>So can I when writing programs assume Element Nodes always are before Text
>Nodes?
Nope.
Jason at 2007-11-11 23:30:13 >
# 2 Re: DOM and the order of its Nodes
Thanx Jason

I am actually a bit confused, I didn't understand one part:
In the DOM specifications from the W3 consortium Element nodes are specified
before Text nodes.

If they are obliged to put them in this order, why can't I rely on them
always beeing in that order?

Cheers

Fredrik

"Jason" <jason@creative_nospam_corp.com> escribi en el mensaje
news:3cade67a$1@10.1.10.29...
>
> "Fredrik" <fredrik@cimade.com> wrote:
> >Does anyone know if there is a fixed order between the different types of
> >DOM Nodes?
> I know.
>
> >Are the manufactures of Parsers obliged to put the different Node types
> in a
> >special order?
> Yep. It's the same order you get when you read the XML document serially.
>
>
> >Are DOM Element Nodes always to be before DOM Text Nodes?
> Nope. Otherwise, the document you read in could not be the same as the
document
> you write out.
>
> >In the W3 documents they place the nodes in this logical order, but I
can't
> >find anywhere in either DOM level1 or Level2 W3 documentation that
> >explicitly says so. No sort functions exist in the Parser I use (Xercex
> for
> >C++), so if I can't rely 100% on them beeing in the same order I have to
> >sort them.
> The nodes are in the order in which they appear in the XML document.
>
> >So can I when writing programs assume Element Nodes always are before
Text
> >Nodes?
> Nope.
Fredrik at 2007-11-11 23:31:13 >
# 3 Re: DOM and the order of its Nodes
Does the specification say they come first? 'A' comes before 'B' in the Alphabet
but it can come before or after B or not at all in words.

XML is just a data definition language. Your parser and program will need
to do the rest.

"Fredrik" <fredrik@cimade.com> wrote:
>Thanx Jason
>
>I am actually a bit confused, I didn't understand one part:
>In the DOM specifications from the W3 consortium Element nodes are specified
>before Text nodes.
>
>If they are obliged to put them in this order, why can't I rely on them
>always beeing in that order?
>
>Cheers
>
>Fredrik
>
>
>"Jason" <jason@creative_nospam_corp.com> escribi en el mensaje
>news:3cade67a$1@10.1.10.29...
>>
>> "Fredrik" <fredrik@cimade.com> wrote:
>> >Does anyone know if there is a fixed order between the different types
of
>> >DOM Nodes?
>> I know.
>>
>> >Are the manufactures of Parsers obliged to put the different Node types
>> in a
>> >special order?
>> Yep. It's the same order you get when you read the XML document serially.
>>
>>
>> >Are DOM Element Nodes always to be before DOM Text Nodes?
>> Nope. Otherwise, the document you read in could not be the same as the
>document
>> you write out.
>>
>> >In the W3 documents they place the nodes in this logical order, but I
>can't
>> >find anywhere in either DOM level1 or Level2 W3 documentation that
>> >explicitly says so. No sort functions exist in the Parser I use (Xercex
>> for
>> >C++), so if I can't rely 100% on them beeing in the same order I have
to
>> >sort them.
>> The nodes are in the order in which they appear in the XML document.
>>
>> >So can I when writing programs assume Element Nodes always are before
>Text
>> >Nodes?
>> Nope.
>
>
MarkN at 2007-11-11 23:32:17 >