Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9267109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:28:25+00:00 2026-06-18T14:28:25+00:00

I’m using XmlParser to read in an XML document that has some content like

  • 0

I’m using XmlParser to read in an XML document that has some content like this:

<instructions size='1'>
   <instruction key='manifest'>
      Bundle-SymbolicName: org.slf4j.api&#xA;Bundle-Version: 1.6.4.v20120130-2120
   </instruction>
</instruction>

Notice on the 3rd line there is entity for newline, &#xA;

The problem is when I use Groovy’s XmlNodePrinter to print out this document (in my case I’ve made changes elsewhere to the document), the node printer will print out the text node and use a real newline instead of %#xA;

<instructions size='1'>
   <instruction key='manifest'>
      Bundle-SymbolicName: org.slf4j.api
Bundle-Version: 1.6.4.v20120130-2120
   </instruction>
</instruction>

I have set the trimWhitespace=false for the XmlParser object and also set preserveWhitespace=true for XmlNodePrinter however this doesn’t change the aforementioned behavior.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:28:26+00:00Added an answer on June 18, 2026 at 2:28 pm

    You can wrap the text inside <![CDATA...]]>:

    <instructions size='1'>
    
       <instruction key='manifest'> 
       <![CDATA[       
           Bundle-SymbolicName: org.slf4j.api&amp;#xA;Bundle-Version: 1.6.4.v20120130-2120 
       ]]>
       </instruction>
    </instructions>
    

    I’m testing it using the following the code:

    def out = new StringWriter() 
    def xml = new XmlParser().parseText(new File("file.xml").text) 
    def printer = new XmlNodePrinter(new PrintWriter(out)) 
    printer.print(xml) 
    println out.toString() 
    

    The output is as expected:

    <instructions size="1">
       <instruction key="manifest">
          Bundle-SymbolicName: org.slf4j.api&amp;#xA;Bundle-Version: 1.6.4.v20120130-2120
       </instruction>
    </instructions>
    

    RESPOND TO COMMENT:

    If you really have no choice, than you can extends XmlNodePrinter (this is a Java class) and create Groovy code such as:

    class MyXmlNodePrinter extends XmlNodePrinter {
       MyXmlNodePrinter(PrintWriter out) {
          super(out)
       }
    
       void printSimpleItem(Object value) {
          value = value.replaceAll("\n", "&#xA;")
          out.print(value)
       }
    }
    
    def out = new StringWriter() 
    def xml = new XmlParser().parseText(new File("file.xml").text) 
    def printer = new MyXmlNodePrinter(new PrintWriter(out)) 
    printer.print(xml) 
    println out.toString() 
    

    The output of this code is:

    <instructions size="1">
       <instruction key="manifest">
          Bundle-SymbolicName: org.slf4j.api&#xA;Bundle-Version: 1.6.4.v20120130-2120
       </instruction>
    </instructions>
    

    That MyXmlNodePrinter is trivial and doesn’t perform escaping, so you may need to copy (and change) private void printEscaped(String s, boolean isAttributeValue) from XmlNodePrinter. You can find the source code of XmlNodePrinter in https://github.com/groovy/groovy-core/blob/master/subprojects/groovy-xml/src/main/java/groovy/util/XmlNodePrinter.java

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm using an ASP request returning a XML file containing some latin characters. By
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am using JSon response to parse title,date content and thumbnail images and place
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.