jkesselm    01/11/29 14:19:14

  Modified:    java/samples/ApplyXPath ApplyXPath.java
  Log:
  Bugzilla4908, patch courtesy of [EMAIL PROTECTED]
  
  Revision  Changes    Path
  1.17      +25 -1     xml-xalan/java/samples/ApplyXPath/ApplyXPath.java
  
  Index: ApplyXPath.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/samples/ApplyXPath/ApplyXPath.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ApplyXPath.java   2001/07/15 08:15:21     1.16
  +++ ApplyXPath.java   2001/11/29 22:19:14     1.17
  @@ -133,7 +133,23 @@
         Node n;
         while ((n = nl.nextNode())!= null)
         {         
  -        serializer.transform(new DOMSource(n), new StreamResult(System.out));
  +     if (isTextNode(n)) {
  +         // DOM may have more than one node corresponding to a 
  +         // single XPath text node.  Coalesce all contiguous text nodes
  +         // at this level
  +         StringBuffer sb = new StringBuffer(n.getNodeValue());
  +         for (
  +           Node nn = n.getNextSibling(); 
  +           isTextNode(nn);
  +           nn = nn.getNextSibling()
  +         ) {
  +           sb.append(nn.getNodeValue());
  +         }
  +         System.out.print(sb);
  +     }
  +     else {
  +       serializer.transform(new DOMSource(n), new StreamResult(System.out));
  +     }
           System.out.println();
         }
         System.out.println("</output>");
  @@ -144,6 +160,14 @@
       }
     }
     
  +  /** Decide if the node is text, and so must be handled specially */
  +  static boolean isTextNode(Node n) {
  +    if (n == null)
  +      return false;
  +    short nodeType = n.getNodeType();
  +    return nodeType == Node.CDATA_SECTION_NODE || nodeType == Node.TEXT_NODE;
  +  }
  +
     /** Main method to run from the command line.    */
     public static void main (String[] args)
       throws Exception
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to