Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML pretty-print: Several pretty-print runs create additional newlines in each run #11

Open
henningit opened this issue Nov 20, 2015 · 2 comments

Comments

@henningit
Copy link

It's due to the namespace attribute: if a XML file contains a namespace attribute then each iteration of a pretty-print run adds a newline \n to the result file. I've adjusted the pretty-data/test/test_xml.js to show the issue:

var xml = '<?xml version="1.0" encoding="UTF-8" ?>      <!DOCTYPE foo SYSTEM "Foo.dtd"><a>          <b>bbb</b>   <!-- comment --><c/><d><soapenv:Envelope xmlns:soapenv="http://xxx" xmlns:xsd="http://yyy" xmlns:xsi="http://zzz"></soapenv>       </d><e>        <![CDATA[ <z></z> ]]></e><f><g></g></f></a>';
var pp_xml  = require('../pretty-data').pd.xml(xml);
var pp2_xml  = require('../pretty-data').pd.xml(pp_xml);
var pp3_xml  = require('../pretty-data').pd.xml(pp2_xml);

console.log('\n==============================================================================\n');
console.log('\n/*------- Original XML string: -------*/\n\n' + xml + '\n');
console.log('\n/*------- Beautified XML -------------*/\n\n' + pp_xml  + '\n');
console.log('\n/*------- Beautified twice XML -------------*/\n\n' + pp2_xml  + '\n');
console.log('\n/*------- Beautified 3 times XML -------------*/\n\n' + pp3_xml  + '\n');
console.log('\n===============================================================================\n');

Result:

/*------- Beautified XML -------------*/

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE foo SYSTEM "Foo.dtd">
<a>
  <b>bbb</b>
  <!-- comment -->
  <c/>
  <d>
    <soapenv:Envelope
      xmlns:soapenv="http://xxx"
      xmlns:xsd="http://yyy"
      xmlns:xsi="http://zzz">
    </soapenv>
  </d>
  <e>
    <![CDATA[ <z></z> ]]>
  </e>
  <f>
    <g></g>
  </f>
</a>


/*------- Beautified twice XML -------------*/

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE foo SYSTEM "Foo.dtd">
<a>
  <b>bbb</b>
  <!-- comment -->
  <c/>
  <d>
    <soapenv:Envelope

      xmlns:soapenv="http://xxx"

      xmlns:xsd="http://yyy"

      xmlns:xsi="http://zzz">
    </soapenv>
  </d>
  <e>
    <![CDATA[ <z></z> ]]>
  </e>
  <f>
    <g></g>
  </f>
</a>


/*------- Beautified 3 times XML -------------*/

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE foo SYSTEM "Foo.dtd">
<a>
  <b>bbb</b>
  <!-- comment -->
  <c/>
  <d>
    <soapenv:Envelope


      xmlns:soapenv="http://xxx"


      xmlns:xsd="http://yyy"


      xmlns:xsi="http://zzz">
    </soapenv>
  </d>
  <e>
    <![CDATA[ <z></z> ]]>
  </e>
  <f>
    <g></g>
  </f>
</a>

I expect that the 2nd and 3rd application of the pretty-print to this XML does not change the XML anymore. One application should be sufficient.

I've found this issue in version 0.40.0.

@xclayl
Copy link

xclayl commented Mar 1, 2018

I found a similar issue. This sample below keeps growing. I guess the mixing text and tags is causing it.

        <target state="new">Company Details
          
          
          <x id="START_TAG_SPAN" ctype="x-span" equiv-text="&lt;span>"/>
          <x id="START_TAG_BUTTON" ctype="x-button" equiv-text="&lt;button>"/>×
          
          
          <x id="CLOSE_TAG_BUTTON" ctype="x-button" equiv-text="&lt;/button>"/>
          <x id="CLOSE_TAG_SPAN" ctype="x-span" equiv-text="&lt;/span>"/>
        </target>

@duncdrum
Copy link

first minifying and then prettifying also doesn't solve the problem see #9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants