When using Xerces, how can I validate the text in createTextNode()

A

Avi U

I'm creating a DOM document and I'm looking for a way to get an
exception when I use ileagal characters.
The method DOMElement->createElement() throw exception when I have an
ileagal unicode character: 0x01 (which is good), but when I create a
text node by calling:
DOMText->createTextNode() I don't get an exception (which is bad).

What is the best way to make sure that when creating the document only
valid characters are used?

Thanks,
Avi
 
M

Martin Honnen

Avi said:
I'm creating a DOM document and I'm looking for a way to get an
exception when I use ileagal characters.
The method DOMElement->createElement() throw exception when I have an
ileagal unicode character: 0x01 (which is good), but when I create a
text node by calling:
DOMText->createTextNode() I don't get an exception (which is bad).

Looking at the W3C DOM Core specification it indeeds suggests that
createElement needs to throw an exception while createTextNode is not
supposed to do that.
I don't use Xerces C (assuming that you do that from the syntax above)
but I have tried some other DOM implementations (MSXML 4, MS .NET,
Mozilla, Java SDK 1.4) and only MSXML 4 throws an exception when I try
xmlDocument.createTextNode("\u0001a")
(I have used Javascript, Java and C# so \u0001 is the character with
Unicode code number 1), the other implementations let that pass.
I am not sure what is the proper case to deal with that.
 
M

Martin Honnen

Avi said:
I'm creating a DOM document and I'm looking for a way to get an
exception when I use ileagal characters.
The method DOMElement->createElement() throw exception when I have an
ileagal unicode character: 0x01 (which is good), but when I create a
text node by calling:
DOMText->createTextNode() I don't get an exception (which is bad).

I have searched on the W3C DOM mailing list and it is indeed a
deliberate decision that you can create not well-formed context in text
nodes with createTextNode:
http://lists.w3.org/Archives/Public/www-dom/2001JulSep/0172.html

So it seems you need to take care of that in your application, a DOM
implementation is not going to help you.

I can't tell whether Xerces C provides any extensions to DOM to check
strings for characters not allowed in XML.
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,052
Latest member
KetoBeez

Latest Threads

Top