Commons Digester
  1. Commons Digester
  2. DIGESTER-120

digesting xml content with NodeCreateRule swallows spaces.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8
    • Fix Version/s: 1.8.1
    • Labels:
      None
    • Environment:

      jdk 1.4.2_08, digester 1.8

      Description

      i need to process an xml file that contains entities: ie:

      <?xml version="1.0" encoding="UTF-8"?>
      <top>
      <body>A A</body>
      </top>

      i'm using digester as follows:

      Digester digester = new Digester ();
      digester.addRule ("top", new ObjectCreateRule (MyContent.class));
      digester.addRule ("top/body", new NodeCreateRule ());
      digester.addSetNext ("top/body", "setBody");

      then
      ...
      digester.parse (file);

      MyContent class transforms the node into text as follows:

      public class MyContent
      {
      public void setBody (Element node)

      { String content = serializeNode (node); System.out.println (content); }

      ...
      }

      the content displayed is in this case: <body>AA</body>

      if the body was encoded in the xml file as: <top><body>A A</body></top>, the content would then be correctly displayed as:
      <body>A A</body>

      looking at the NodeCreateRule.NodeBuilder.characters () implementation, the following code generates the problem:
      String str = new String(ch, start, length);
      if (str.trim().length() > 0) {
      top.appendChild(doc.createTextNode(str));

      when entities are being used; the characters () method is called for 'A', ' ' and 'A' in the first case. in the second case, it is called once with 'A A'.

      1. simple.xml
        0.1 kB
        Nguyen Thanh Son Daniel
      2. digester-patch.txt
        4 kB
        Simon Kitching

        Activity

        Nguyen Thanh Son Daniel created issue -
        Simon Kitching made changes -
        Field Original Value New Value
        Attachment digester-patch.txt [ 12377968 ]
        Nguyen Thanh Son Daniel made changes -
        Attachment simple.xml [ 12377970 ]
        Simon Kitching made changes -
        Fix Version/s 1.8.1 [ 12312580 ]
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Rahul Akolkar made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Nguyen Thanh Son Daniel
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development