Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2592

XmlNodePrinter doesn't escape special characters in attributes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.4
    • 1.5.5, 1.6-beta-1
    • XML Processing
    • None

    Description

      As per the mailing list:

      import groovy.xml.StreamingMarkupBuilder
      
      doc = """<Field Text="&lt;html&gt;Some Text&lt;/html&gt;" />"""
        
      def d = new XmlParser().parseText(doc)
      
      def writer = new StringWriter()
      new XmlNodePrinter(new PrintWriter(writer)).print(d)
      def result = writer.toString()   
      
      println result
      
      d = new XmlSlurper().parseText(doc)
      
      writer = new StringWriter()
      writer << new StreamingMarkupBuilder().bind {out << d}
      result = writer.toString()
      
      println result
      

      produces:

      <Field Text="<html>Some Text</html>"/>
      
      <Field Text='&lt;html&gt;Some Text&lt;/html&gt;'></Field>
      

      Attachments

        Activity

          People

            paulk Paul King
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: