DTD or Schema -- Ignore Undefined Tags

Discussion in 'XML' started by gregmcmullinjr@gmail.com, Dec 13, 2006.

  1. Guest

    I am wondering if there is a way to use a DTD or Schema to instruct an
    XML parser to ignore tags that are not defined.

    That is, if my list of acceptable tags is <body> and <content>, then in
    the following example:

    <body>
    We may have some text <b>and some <u>other tags</u></b>
    <content> but I want the text and undefined tags to be part of the
    text-node
    of the body tag.
    </content>
    </body>

    So the tree would be like:
    <body>
    #Text
    <content>
    #Text
    </content>
    </body>

    I want the first text node to contain "We may have some text <b>and
    some <u>other tags</u></b>"

    Is there some way of doing this with Schemas or DTDs? Or perhaps using
    a stylesheet?

    Using a stylesheet I would need to do find a way of matching all tags
    that arent in a certain list and then re-writing them with $lt;
    entities I suppose, but I'm really not sure what the best way to do
    this is.

    Any help is appreciated,

    Greg
    , Dec 13, 2006
    #1
    1. Advertising

  2. wrote:
    > Using a stylesheet I would need to do find a way of matching all tags
    > that arent in a certain list and then re-writing them with $lt;
    > entities I suppose


    Not a good solution. Elements are semantically meaningful; &lt;foo&gt;
    is NOT the same thing as <foo>.

    If you're working with schemas, you can use xsd:any with lax validation
    to indicate that the contents of certain elements should be accepted
    even if not valid.

    Another alternative, of course, is to insist only on well-formed
    documents and not attempt to validate them.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Dec 13, 2006
    #2
    1. Advertising

  3. Peter Flynn Guest

    wrote:
    > I am wondering if there is a way to use a DTD or Schema to instruct an
    > XML parser to ignore tags that are not defined.


    No.A schema or DTD is for doing exactly the reverse: enforcing the use
    only of elements that have been declared.

    BTW elements, not "tags": see http://xml.silmaril.ie/authors/makeup/

    > That is, if my list of acceptable tags is <body> and <content>, then in
    > the following example:
    >
    > <body>
    > We may have some text <b>and some <u>other tags</u></b>
    > <content> but I want the text and undefined tags to be part of the
    > text-node
    > of the body tag.
    > </content>
    > </body>
    >
    > So the tree would be like:
    > <body>
    > #Text
    > <content>
    > #Text
    > </content>
    > </body>


    If you want to do this, process the XML in non-validated mode, just
    well-formed but with no DTD or schema.

    > I want the first text node to contain "We may have some text <b>and
    > some <u>other tags</u></b>"
    >
    > Is there some way of doing this with Schemas or DTDs? Or perhaps using
    > a stylesheet?


    XSLT is your friend.

    > Using a stylesheet I would need to do find a way of matching all tags
    > that arent in a certain list and then re-writing them with $lt;
    > entities I suppose, but I'm really not sure what the best way to do
    > this is.


    Whoah! This is a different question entirely. Are you implying that you
    still want to *keep* the otherwise unrecognised element markup? Your
    example above implied that you wanted to discard it.

    You definitely don't want to fiddle with making them all &lt;...&gt; --
    that way madness lies. See http://xml.silmaril.ie/authors/html/

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
    Peter Flynn, Dec 14, 2006
    #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. KatB

    Ignore DTD pi in xsl transform?

    KatB, Oct 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    700
  2. Markus
    Replies:
    1
    Views:
    1,528
    Markus
    Nov 23, 2005
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,251
    Stanimir Stamenkov
    Apr 25, 2005
  4. pramodr
    Replies:
    3
    Views:
    839
    Peter Flynn
    Apr 5, 2009
  5. Rob Meade
    Replies:
    6
    Views:
    264
    Rob Meade
    Mar 1, 2004
Loading...

Share This Page