eerohele / exalt

A Sublime Text plugin for validating and formatting XML documents
MIT License
22 stars 3 forks source link

Canonical xml using Exalt #2

Closed cksachdev closed 7 years ago

cksachdev commented 7 years ago

Is it possible to Canonicalize xml using Exalt? I have seen that lxml is a dependency. I can't find any option to canonicalize xml.

eerohele commented 7 years ago

Not at the moment. I can look into it, though.

cksachdev commented 7 years ago

@eerohele Thanks, looking forward to it. In the meantime, do you know any such tools which can help me canonicalize the xml in osx.

eerohele commented 7 years ago

Something like this should work:

$ brew install libxml2
$ xmllint --c14n11 myfile.xml

Provided that you have Homebrew installed.

eerohele commented 7 years ago

I've released version 0.3.0, which adds support for canonicalizing XML.

It might take a while for it to appear in Package Control, but when it does, can you please give it a go and let me know whether it works for you?

You can canonicalize a well-formed XML document by selecting "Exalt: Canonicalize Document" from the Sublime Text command palette.

cksachdev commented 7 years ago

Thanks, It works for me, there is an issue that it removes the CDATA. Here is a test xml

<?xml version="1.0"?>
<theme>
  <controller type="data" name="dictionary" id="dictionary" ><![CDATA[{}]]></controller>
</theme>

After canonical run

<theme>
  <controller id="dictionary" name="dictionary" type="data">{}</controller>
</theme>

Please check why CDATA is removed, it should just arrange the properties in sorted order and should preserve the content as it is.

eerohele commented 7 years ago

It seems that the W3C specification for canonical XML dictates that "CDATA sections are replaced with their character content", so the current behavior is correct.

Anyway, it's libxml2 that does the actual canonicalization, so there's little I can do to modify the behavior.