You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "Steve Lawrence (Jira)" <ji...@apache.org> on 2025/10/20 15:35:00 UTC

[jira] [Commented] (DAFFODIL-2977) Empty XML element behavior has changed. Needs to be specific.

    [ https://issues.apache.org/jira/browse/DAFFODIL-2977?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18031193#comment-18031193 ] 

Steve Lawrence commented on DAFFODIL-2977:
------------------------------------------

I have confirmed that the pretty printers for Scala-XML, JDOM, and W3C DOM do output <string/> if an element has no content, and output <string></string> if an element has empty string content. I imagine other XML libraries do that as well.

I tested the Daffodil CLI back to 3.0.0 and all of our infoset outputters have not changed behavior, always outputting <string></string> for zero-length string elements. The one exception is W3C DOM, which output <string /> in 3.0.0, but output <string></string> for 3.1.0 and later. So for the most part we have been pretty consistent since 3.1.0 which was released in 2021.

We could do as you suggest so that we output <string />, but considering this has been our behavior for a fairly long time, I'm hesitant to change it now without a good reason. Especially since if there any tools that compare the output of the CLI, things will change and could break a lot of tests.

I think there's also an argument that although they are semantically the same, a DOM tree with Text("") as a child has a different implication than a DOM tree with no child--i.e. there is an explicit child with empty string as the text. Feels like being explicit about there being a text element might be technically more correct.

If we do want to support this, we should probably add it as a flag that users can enable and keep the current behavior as the default. We still don't have a great way to pass in these kinds of options to inputters/outputters (DAFFODIL-2234). So I would suggest either mark this as won't fix, or remove it from 4.1.0 and plan to add the option in the future once we have a better way to configure our outputters.

> Empty XML element behavior has changed. Needs to be specific.
> -------------------------------------------------------------
>
>                 Key: DAFFODIL-2977
>                 URL: https://issues.apache.org/jira/browse/DAFFODIL-2977
>             Project: Daffodil
>          Issue Type: Bug
>          Components: Back End
>    Affects Versions: 3.10.0
>            Reporter: Mike Beckerle
>            Assignee: Steve Lawrence
>            Priority: Major
>             Fix For: 4.1.0
>
>
> XML output used to be `<foo></foo>` but now is `<foo/>` or vice versa.
> Needs to be definite one or the other. (I recommend `<foo/>`
> For any XML outputter, we need to control this behavior so that it is definitely one or the other and doesn't change from release to release. 
> It's also possible that we should be special casing the filling in of string-type elements so that if the string value is length 0 we don't output any child at all.  Filling in a child string object inside a DOM or JDOM node object where that child string is of zero length is going to perhaps cause this `<string></string>` vs. `<string/>` behavior. But in XML these are indistinguishable, so we should catch this case and not attach the child at all. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)