You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by "EXT-Pennington, Dale K" <da...@boeing.com> on 2007/09/21 18:10:11 UTC

DOM Layout Assumptions ?

Folks,

I want to know if the following is a reasonable assumption :

Given an element specified in a schema as

<xs:element name="x" type="xs:long">

And decoding an XML document into a DOM using that schema as the
validation rule.

If I find the Element Node in the DOM tree with name x, can I safely
assume it only has one Child Node which is a text node containing X's
value.

Obviously, assuming such would make my code simpler, but I do not want
to insert bugs by making wrong assumptions.

Thanks

Dale Pennington

Re: DOM Layout Assumptions ?

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi Dale,

EXT-Pennington, Dale K <da...@boeing.com> writes:

> So I guess I will need to check all child nodes of the element, and if I
> find more than one text node, either merge them or declare an error.

You can use the getTextContent() function which will merge the text
from multiple nodes for you. Note, however, that this function will
allocate a chunk of memory which stays allocated for the lifetime of
the DOM document. See the following blog post for more information:


http://codesynthesis.com/~boris/blog/2006/11/28/xerces-c-dom-potholes/


Boris

-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding

RE: DOM Layout Assumptions ?

Posted by "EXT-Pennington, Dale K" <da...@boeing.com>.
 

> -----Original Message-----
> From: Michael Glavassevich [mailto:mrglavas@ca.ibm.com] 
> Sent: Friday, September 21, 2007 11:34 AM
> To: c-users@xerces.apache.org
> Subject: Re: DOM Layout Assumptions ?
> 
> Dale,
> 
> Considering that this is valid:
> 
> <x>200<!-- commment in the middle of a value -->00</x>
> 
> even for a valid document (which I think you meant to say) 
> you can't assume that. This is just one example. I can think 
> of at least a few others which break your assumption.
> 
> Thanks.
> 
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
> 
Ouch,

So I guess I will need to check all child nodes of the element, and if I
find more than one text node, either merge them or declare an error.
(Given the actual method these XML messages are generated, I would never
expect to see your scenario above so I think I will call it an error
until someone forces me to write a more robust handler).

Dale

Re: DOM Layout Assumptions ?

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Dale,

Considering that this is valid:

<x>200<!-- commment in the middle of a value -->00</x>

even for a valid document (which I think you meant to say) you can't assume
that. This is just one example. I can think of at least a few others which
break your assumption.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"EXT-Pennington, Dale K" <da...@boeing.com> wrote on 09/21/2007
12:10:11 PM:

> Folks,
>
> I want to know if the following is a reasonable assumption :
>
> Given an element specified in a schema as
>
> <xs:element name="x" type="xs:long">
>
> And decoding an XML document into a DOM using that schema as the
> validation rule.
>
> If I find the Element Node in the DOM tree with name x, can I safely
> assume it only has one Child Node which is a text node containing X's
> value.
>
> Obviously, assuming such would make my code simpler, but I do not want
> to insert bugs by making wrong assumptions.
>
> Thanks
>
> Dale Pennington