Xalan - empty element

Discussion in 'XML' started by Albert Greinöcker, Sep 9, 2006.

  1. Hi NG,

    how can I force Xalan (Java) not to create an empty element when there is
    nothing between begin and end tag, which means that e.g.

    <myTag></myTag>

    ....does not become...

    <myTag/>

    ?

    thx,
    Albert
    Albert Greinöcker, Sep 9, 2006
    #1
    1. Advertising

  2. Albert Greinöcker

    Soren Kuula Guest

    Albert Greinöcker wrote:
    > Hi NG,
    >
    > how can I force Xalan (Java) not to create an empty element when there is
    > nothing between begin and end tag, which means that e.g.
    >
    > <myTag></myTag>
    >
    > ...does not become...
    >
    > <myTag/ >


    They are both exactly the same; an empty element. the string
    representations (serializations) are different; the meaning is the same.

    Maybe there is an option in the class you use for serializing. Anyway,
    that is where it happens.

    Søren
    Soren Kuula, Sep 9, 2006
    #2
    1. Advertising

  3. Hi Soren,

    yes, I agree, it should be, but I observed that some browsers (particularly
    the IE 6) do have problems with some empty tags (in case of <script/>,
    <textarea/>)

    Albert
    Albert Greinöcker, Sep 9, 2006
    #3
  4. Albert Greinöcker wrote:
    > how can I force Xalan (Java) not to create an empty element when there is
    > nothing between begin and end tag, which means that e.g.
    > <myTag></myTag>
    > ...does not become...
    > <myTag/>


    If it really matters to you, you can try to find or write a SAX
    serializer that handles this as a special case, ask Xalan to output SAX,
    and plug the two together. Or adapt Xalan's existing serializer code;
    one of the advantages of open-source projects is that you can alter them
    and/or use them as a starting point for specialized tools. (You might
    want to compare the XML and HTML serializers; I think the latter has
    some similar tweaks.)

    But personally, I would suggest you fix whatever downstream tool isn't
    correctly handling <myTag/>. XML considers the two forms precisely
    equivalent to each other, so you're asking for a difference that should
    make no difference.

    (Xalan has its own mailing list, which is generally a better place to
    ask questions which are specific to that processor. But this one's a
    general enough issue that I thought it was worth answering here.)




    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Sep 9, 2006
    #4
  5. Albert Greinöcker wrote:


    > yes, I agree, it should be, but I observed that some browsers (particularly
    > the IE 6) do have problems with some empty tags (in case of <script/>,
    > <textarea/>)


    Well if you send text/html to IE then it parses according to SGML/HTML
    rules and not XML rules and HTML mandates <script
    type="text/javascript"></script> and not <script/> or </script />.
    If you send text/xml or application/xml to IE then it parses with MSXML
    as its XML parser and I am sure that does not have any problems with
    <script/> or <textarea/>, only it only sees those as XML elements
    without any meaning and not something to render.

    If you use XSLT to transform XML to HTML then make sure you use e.g.
    <xsl:eek:utput method="html"/>
    and use HTML elements like e.g. script in no namespace, that way they
    will end up as <script></script> when the XSLT processor serializes the
    XSLT result tree.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Sep 9, 2006
    #5
  6. Martin Honnen wrote:
    > If you use XSLT to transform XML to HTML then make sure you use e.g.
    > <xsl:eek:utput method="html"/>


    Absolutely. Or generate XHTML and make sure the downstream tool supports
    that newer syntax.


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Sep 9, 2006
    #6
  7. Albert Greinöcker

    Peter Flynn Guest

    Albert Greinöcker wrote:
    > Hi NG,
    >
    > how can I force Xalan (Java) not to create an empty element when there is
    > nothing between begin and end tag, which means that e.g.
    >
    > <myTag></myTag>
    >
    > ...does not become...
    >
    > <myTag/>


    Why? They are both the same in effect (perhaps not in intention :)

    ///Peter
    Peter Flynn, Sep 9, 2006
    #7
  8. Albert Greinöcker

    Peter Flynn Guest

    Albert Greinöcker wrote:
    > Hi Soren,
    >
    > yes, I agree, it should be, but I observed that some browsers (particularly
    > the IE 6) do have problems with some empty tags (in case of <script/>,
    > <textarea/>)


    Don't use broken software for XML.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
    Peter Flynn, Sep 9, 2006
    #8
    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. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,012
    Klaus Johannes Rusch
    Jul 16, 2003
  2. cvissy
    Replies:
    0
    Views:
    601
    cvissy
    Nov 16, 2004
  3. Lukas
    Replies:
    3
    Views:
    787
    spiff
    Nov 10, 2005
  4. Xh
    Replies:
    7
    Views:
    1,051
    Joseph Kesselman
    Mar 19, 2007
  5. HANM
    Replies:
    2
    Views:
    697
    Joseph Kesselman
    Jan 29, 2008
Loading...

Share This Page