Uploaded image for project: 'XMLBeans'
  1. XMLBeans
  2. XMLBEANS-524

Bug with setLoadStripWhitespace ? Or expected behaviour?

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • Version 3.0.1
    • None
    • XmlObject
    • None
    • windows 8.1 using java SE 1.8

    Description

      Hi,

      I noticed similar problems have been reported before, but I am not so sure it is correct yet.

      I would expect tag values to be unaffected when stripping whitespace with the setLoadStripWhitespace option.  XMLBeans trim values as well as whitespace between tags.

      Here is my example code:

      String xmlText = "<Note>\n" +
       " <NoteType>Fred</NoteType>\n" +
       " <NoteText> Note with newlines\n" +
       "and leading and\n" +
       "trailing white space </NoteText>\n" +
       " </Note>";
      
      System.out.println("Original text = [" + xmlText + "]");
      System.out.println("\n");
      
      XmlObject test = XmlObject.Factory.parse(xmlText);
      System.out.println("parsed text = [" + test.xmlText() + "]");
      System.out.println("\n");
      
      XmlOptions options = new XmlOptions().setLoadStripWhitespace();
      XmlObject test3 = XmlObject.Factory.parse(xmlText, options);
      System.out.println("with setLoadStripWhitespace() = [" + test3.xmlText() + "]");

      It prints this:

       

      Original text = [<Note>
       <NoteType>Fred</NoteType>
       <NoteText> Note with newlines
      and leading and
      trailing white space </NoteText>
       </Note>]
      
      parsed text = [<Note>
       <NoteType>Fred</NoteType>
       <NoteText> Note with newlines
      and leading and
      trailing white space </NoteText>
       </Note>]
      
      with setLoadStripWhitespace() = [<Note><NoteType>Fred</NoteType><NoteText>Note with newlines
      and leading and
      trailing white space</NoteText></Note>]
      

       

      I would expect the leading space in the NoteText should be preserved, i.e. the space before "Note with" and the last space in that same text.

      I am in other words looking to compact the XML itself without in any way touching the values of the tags.

      By the way, very happy to see XMLBeans un-retired

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              runegellein Rune Gellein
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: