>    I'm using Xerces-C to parse my XML Files. But if the files is
>formated with ENTER at final of each XML tags, the DOM Parser get the
>ENTER like a child node. How can I do to formated my XML files with
>ENTER at final of the tags, without any problems.

That's correct XML behavior. An XML parser is _required_ to pass along
whitespace as part of the document's content.

If you're validating against a DTD or schema, the parser is supposed to
flag "whitespace in element content". SAX handles this, calling it
"ignorable whitespace" (bad name, unfortunately). Current versions of the
standard DOM API don't handle it, though DOM Level 3 intends to.

Possible workarounds:

1) Xerces-J has a custom feature that allows suppressing "ignorable"
whitespace. (See http://xml.apache.org/xerces-j/features.html). I don't
know if Xerces-C has something similar. Of course that's not portable to
other parsers, and doesn't help you if the document has no DTD, is not
being validated, or is a DOM built by something other than the parser.

2) You could write a SAX-to-DOM builder, and filter the SAX events to
discard the whitespace. That would allow you to use hardcoded information
about what whitespace is and isn't meaningful, rather than relying on the
DTD... which has both advantages and disadvantages. (DOM L3 intends to
support a "filtering" API in its Load/Save chapter, which would be another
way of achieving the same effect.)

3) You could let the DOM be built, then walk through it removing the
whitespace you don't want to see. A loop based on the DOM's NodeIterator
might be simplest, since you could set the NodeIterator to show only text
nodes and further add a user-written filter routine that showed only
whitespace text nodes. Again, it'd be your responsibility to determine
which whitespace is or isn't significant... and since the DOM doesn't
display the DTD information (another feature expected in Level 3) you'd
have to hardcode your logic.

4) Or you could simply write your program so it understands that whitespace
text nodes may be present, and knows how to deal with that.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to