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

Discussion in 'XML' started by Avi U, Jan 13, 2004.

  1. Avi U

    Avi U Guest

    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
    Avi U, Jan 13, 2004
    #1
    1. Advertising

  2. Avi U wrote:

    > 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.
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 13, 2004
    #2
    1. Advertising

  3. Avi U wrote:

    > 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.
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 13, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danny
    Replies:
    11
    Views:
    811
  2. Martin Honnen

    Re: DOM CreateTextNode with Unicode

    Martin Honnen, Feb 29, 2008, in forum: XML
    Replies:
    0
    Views:
    372
    Martin Honnen
    Feb 29, 2008
  3. Thomas 'PointedEars' Lahn

    Re: DOM CreateTextNode with Unicode

    Thomas 'PointedEars' Lahn, Mar 1, 2008, in forum: XML
    Replies:
    0
    Views:
    488
    Thomas 'PointedEars' Lahn
    Mar 1, 2008
  4. DKM
    Replies:
    10
    Views:
    202
  5. Jeff

    newbie: createTextNode & Div

    Jeff, Nov 15, 2005, in forum: Javascript
    Replies:
    2
    Views:
    78
    web.dev
    Nov 15, 2005
Loading...

Share This Page