Giter Club home page Giter Club logo

sublimetext_indentxml's Introduction

SublimeText Indent plugin

What is the goal of Indent plugin? Short answer is converting this XML

<root><node attr="1" attr2="4"><node /></node></root>

to this:

<root>
    <node attr="1" attr2="4">
	    <node/>
    </node>
</root>

Looks good? It also can convert this JSON

{ "root": [ { "field": "val1", "field2": "val2" }, { "arr": [1, 3, "three"] }] }

to this

{
    "root": [
        {
            "field": "val1",
            "field2": "val2"
        },
        {
            "arr": [
                1,
                3,
                "three"
            ]
        }
    ]
}

Want more? It can indent only selected text - including multiple selections and even mixed XML / JSON selections. It is smart enough to recognize XML or JSON even if you are editing plain text. Indent plugin won't mess up your keyboard shortcuts because it uses "chord" command Ctrl+K, Ctrl+F (this mean hold Ctrl, press K then press F, release Ctrl) and also available in "Selection" menu.

Supported Sublime Text versions

Indent plugin supports both Sublime Text 2 and Sublime Text 3

Installation

Just use Package Control and search for "indent xml" plugin

Usage

Click on Tools->Command Pallette... (or Ctrl+shift+P if you're a keyboard person) and then chose "Indent XML"

Settings

Currently this plugin performs patching of xml.dom.minidom.CDataSection class in order to fix CDATA indenting in toprettyxml function. This can be disabled in indent_xml.Sublime-settings file by setting disable_patch_minidom to true.

Feedback & Support

Available on Github

Contribution

...is always welcome! Same place - Github

License

This software is distributed under MIT license (see License.txt for details)

sublimetext_indentxml's People

Contributors

abloch avatar alek-sys avatar alexandryz avatar bheklilr avatar d-schmidt avatar francoiskha avatar hagfjall avatar hmalphettes avatar jsadeli avatar kinow avatar northlander avatar ronjouch avatar yujiande avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sublimetext_indentxml's Issues

SublimeText3 TypeError: can't concat bytes to str

Traceback (most recent call last):
File "/opt/sublime_text/sublime_plugin.py", line 531, in run_
return self.run(edit)
File "/.config/sublime-text-3/Installed Packages/Indent XML.sublime-package/indentxml.py", line 44, in run
File "
/.config/sublime-text-3/Installed Packages/Indent XML.sublime-package/indentxml.py", line 77, in indent
File "~/.config/sublime-text-3/Installed Packages/Indent XML.sublime-package/indentxml.py", line 100, in indent
TypeError: can't concat bytes to str

Doesn't support xsi:type attributes

Example:

<?xml version="1.0" encoding="UTF-8"?><root type="tag"><properties><property name="namespace" xsi:type="xsd:string">config</property></properties></root>

Causes:

Traceback (most recent call last):
File ".\sublime_plugin.py", line 362, in run_
File ".\indentxml.py", line 32, in run
File ".\indentxml.py", line 48, in indentxml
File ".\xml\dom\minidom.py", line 1928, in parseString
File ".\xml\dom\expatbuilder.py", line 940, in parseString
File ".\xml\dom\expatbuilder.py", line 223, in parseString
xml.parsers.expat.ExpatError: unbound prefix: line 1, column 67

Indent without sorting of attributes

Hey there
I'm not sure whether this is the right place to address this issue, but I did not find any comment function on github.
Thanks for this plugin first of all! Helps me a lot.
there is just one thing: I don't want the plugin to rearrange my attributes of my xml nodes.
Could you tell me where I can disable that feature?
Thx a lot

Jonas

Configurable "new line on element"

It would be nice to be able to configure when an element should trigger a new line after/before it. When indenting XHTML, I do not think anyone would want to trigger a new line on some inline elements such as i and b.

Fail to indent files containing accents

Hi, I'm a french user of Sublime and your marvelous plugin that really helps when dealing with openXML documents.
But the plugin fails to deal with files containing accents like "é", etc..

Traceback (most recent call last):
    File ".\sublime_plugin.py", line 282, in run_
    File ".\indentxml.py", line 37, in run
    File ".\indentxml.py", line 45, in indentxml
    File ".\xml\dom\minidom.py", line 1928, in parseString
    File ".\xml\dom\expatbuilder.py", line 940, in parseString
    File ".\xml\dom\expatbuilder.py", line 223, in parseString
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 1049: ordinal not in range(128)

I'm not a python expert but checking line 45 in indentxml.py I did a slight change that change my life.
pyhton s = parseString(s).toprettyxml() => s = parseString(s.encode( "utf-8" )).toprettyxml()

Don't know if this was a good idea, but a least a suggestion to make your non-english users happy.

All the best
Mr Waz

Optionally Indent attributes

Would be great to be able to specify that XML attributes should also be indented.
I have XML files that are full of attributes. I'd like them to be indented in the following way:

<?xml version="1.0" encoding="UTF-8" ?>
<Reply Success="TRUE" >
   <JobInfo Name="Job 1"
            GUID="{62A160F3-79E8-4358-9073-EDCAE4B4ED75}"
            State="NEX_STARTED"
            Status="STARTED"
            Progress.DWD="32"
            Description="Example Job"
            User="WatchFolder"
            SourceDescription="C : \ _ test . mp4"
            AgentIP="192.168.62.133"
            Priority.DWD="5"
            DeleteProcessedSource.DWD="1"
            StartTime_SCM="2008-05-1519:23:41" />
</ Reply>

Still problems in latest ST 3

This is the traceback:

Traceback (most recent call last):
File "/Users/charlie/Applications/Sublime Text 3.app/Contents/MacOS/sublime_plugin.py", line 531, in run_
return self.run(edit)
File "/Users/charlie/Library/Application Support/Sublime Text 3/Packages/Indent XML/indentxml.py", line 44, in run
s = self.indent(s)
File "/Users/charlie/Library/Application Support/Sublime Text 3/Packages/Indent XML/indentxml.py", line 100, in indent
s = xmlheader.group() + "\n" + s
TypeError: can't concat bytes to str

why this plugin trim the start and the end blank space

<w:t xml:space="preserve"> The database has rows and the cache may have objects.
The database caching logic must know enough to create objects from the database schema. </w:t>

after indent

<w:t xml:space="preserve"><w:t xml:space="preserve">The database has rows and the cache may have objects.
The database caching logic must know enough to create objects from the database schema</w:t>

Include also compressing option

It would be possible to include also a command to compress the XML/JSON to a minified version?

Currently , for JSON at least, this must be done with another plugin which also formats so you end with a duplicate feature...

Fail to indent if the XML contains a CDATA with another XML inside

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "indentxml in /Users/florentviel/Library/Application Support/Sublime Text 3/Installed Packages/Indent XML.sublime-package", line 49, in run
  File "indentxml in /Users/florentviel/Library/Application Support/Sublime Text 3/Installed Packages/Indent XML.sublime-package", line 96, in indent
  File "indentxml in /Users/florentviel/Library/Application Support/Sublime Text 3/Installed Packages/Indent XML.sublime-package", line 93, in indent
  File "X/xml/dom/minidom.py", line 1972, in parseString
  File "X/xml/dom/expatbuilder.py", line 926, in parseString
  File "X/xml/dom/expatbuilder.py", line 221, in parseString
xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 1, column 645

Sublime version: 3

Port to Sublime Text 3

Currently, under Windows 7 x64 / Sublime Text 3 build 3008, IndentXML returns the following error:

Traceback (most recent call last):
  File "C:\sublimetext3\sublime_plugin.py", line 382, in run_
    return self.run(edit)
  File "C:\sublimetext3\Data\Packages\Indent XML\indentxml.py", line 37, in run
    s = self.indentxml(s)
  File "C:\sublimetext3\Data\Packages\Indent XML\indentxml.py", line 43, in indentxml
    xmlheader = re.compile("<\?.*\?>").match(s)
TypeError: can't use a string pattern on a bytes-like object

Also, it looks like Will Bond's PackageControl will require a new package.json to support the 2 vs. 3 difference

doesn't work under Linux

Hi,

your package works great below Windows. But below Linux I got this error message on the console:

Traceback (most recent call last):
File "./sublime_plugin.py", line 351, in run_
File "./indentxml.py", line 32, in run
File "./indentxml.py", line 48, in indentxml
File ".\xml\dom\minidom.py", line 1927, in parseString
File ".\xml\dom\expatbuilder.py", line 32, in
File ".\xml\parsers\expat.py", line 4, in
ImportError: No module named pyexpat

I'm using the latest build (Build 2165).

Any idea?

Cheers,
Magistrate

Not working shows error on console

Traceback (most recent call last):
File "./sublime_plugin.py", line 362, in run_
File "./indentxml.py", line 49, in run
File "./indentxml.py", line 92, in indent
File ".\xml\dom\minidom.py", line 1927, in parseString
File ".\xml\dom\expatbuilder.py", line 32, in
File ".\xml\parsers\expat.py", line 4, in
ImportError: No module named pyexpat

Ubuntu: No module named pyexpat

On Ubuntu 12.04.1 LTS I've received error:
Traceback (most recent call last): File "./sublime_plugin.py", line 362, in run_ File "./indentxml.py", line 32, in run File "./indentxml.py", line 48, in indentxml File ".\xml\dom\minidom.py", line 1927, in parseString File ".\xml\dom\expatbuilder.py", line 32, in <module> File ".\xml\parsers\expat.py", line 4, in <module> ImportError: No module named pyexpat

Looks like Sublime distribution doesn’t include pyexpat module.
Default version of Python used in Ubuntu 12.04 is 2.7.3 so you can't reuse system modules.

XML in one line getting no element found, when XML is invalid

Here's the XML in question:
<OTA_HotelResRQ xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" EchoToken="27516798AC15283F6F96295746FA0774" PrimaryLangID="de-DE" ResStatus="Book" Target="Production" TimeStamp="2014-03-07T19:06:46+01:00" TransactionIdentifier="1236213" Version="1.003" xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 OTA_HotelResRQ.xsd"> Martin Lechner [email protected]

Ziegeleistr. 42 Aichach 86551 DE GR DE

Fail to ident files with empty namespace

ex: <a xmlns=""><b></b></a>

Traceback (most recent call last):
File ".\sublime_plugin.py", line 350, in run_
File ".\indentxml.py", line 37, in run
File ".\indentxml.py", line 48, in indentxml
File ".\xml\dom\minidom.py", line 57, in toprettyxml
File ".\xml\dom\minidom.py", line 1749, in writexml
File ".\xml\dom\minidom.py", line 812, in writexml
File ".\xml\dom\minidom.py", line 301, in _write_data
AttributeError: 'NoneType' object has no attribute 'replace'

No indent xml on package control

I can't find any result for "indent xml" in the package control installer search list. I have other results, but not your plugin. There is no mention of adding a repository or any other step on the site. Is there any reason it wouldn't work?

indent xml

Error when using xml indent

Just installed the package (sublim text 2 / linux) and when i select my xml then do selection => format => indent xml then i got :

Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./indentxml.py", line 44, in run
  File "./indentxml.py", line 96, in indent
ImportError: No module named pyexpat

JSON without string quotes

@alek-sys I have been trying to use indent JSON function for getting the JSON formatted, however looks like it only understands : {"key": value} format. I would want to extend this to be able to handle: {key: value }. Most of the cases, people might be using the JSON as follows rather than the the quoted string format. Does this seem to be in scope for this ?

I would like to contribute.

json indent doesnt work on some files.

big files wont indent ,dont know if its related to the file it self or just because there are too many lines ,here is what i get in console

indent_json

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "indentxml in /Users/Novo/Library/Application Support/Sublime Text 3/Installed Packages/Indent XML.sublime-package", line 49, in run
  File "indentxml in /Users/Novo/Library/Application Support/Sublime Text 3/Installed Packages/Indent XML.sublime-package", line 116, in indent
  File "./json/__init__.py", line 319, in loads
  File "./json/decoder.py", line 352, in decode
  File "./json/decoder.py", line 368, in raw_decode
  File "./json/scanner.py", line 38, in _scan_once
  File "./json/decoder.py", line 176, in JSONObject
ValueError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2)

auto_indent

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "indentxml in /Users/Novo/Library/Application Support/Sublime Text 3/Installed Packages/Indent XML.sublime-package", line 49, in run
  File "indentxml in /Users/Novo/Library/Application Support/Sublime Text 3/Installed Packages/Indent XML.sublime-package", line 77, in indent
  File "indentxml in /Users/Novo/Library/Application Support/Sublime Text 3/Installed Packages/Indent XML.sublime-package", line 116, in indent
  File "./json/__init__.py", line 319, in loads
  File "./json/decoder.py", line 352, in decode
  File "./json/decoder.py", line 368, in raw_decode
  File "./json/scanner.py", line 38, in _scan_once
  File "./json/decoder.py", line 176, in JSONObject
ValueError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2)

xml.parsers.expat.ExpatError: mismatched tag

It fails to indent the XML (RSS) that comes from here :
Does the indentation really ignores whats in CDATA ?

Here's the error that I get :

Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./indentxml.py", line 49, in run
  File "./indentxml.py", line 96, in indent
xml.parsers.expat.ExpatError: mismatched tag: line 1, column 1006

Here is the piece of XML (or you can get it from the link in top of this issue report)

<?xml version="1.0" encoding="ISO-8859-1" ?><?xml-stylesheet type="text/xsl" href="http://www.rssweather.com/xslt.php" ?><?xml-stylesheet type="text/css" href="http://www.rssweather.com/rss.css" ?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Paris, FRANCE Weather</title><link>http://www.rssweather.com/hw3.php?place=paris&amp;state=&amp;country=fr&amp;utm_source=rss&amp;utm_medium=rss</link><description><![CDATA[Current weather, forecasts and alerts delivered using RSS.<p>The weather information for this RSS feed is taken from the National Weather Service (http://weather.noaa.gov/), and powered by HamWeather (http://www.hamweather.com/). </p><h2>Using the Feeds</h2><ul><li>Request Frequency - The feeds are updated once per hour. More frequent requests may result in your access being limited.</li><li>Web Site Usage - If you are using the feed on your web site, you are required to maintain a link to rssWeather.com and hamweather.com</li></ul></b></p>]]></description><ttl>60</ttl><generator>HamWeather (http://www.hamweather.com/)</generator><language>en</language><item><title>Paris, FRANCE Weather :: 25C Fair</title><link>http://www.rssweather.com/hw3.php?place=paris&amp;state=&amp;country=fr&amp;utm_source=rss&amp;utm_medium=rss</link><category>Current Conditions</category><pubDate>Thu, 25 Jul 2013 10:00:00 +0100</pubDate><description>25C Fair</description><content:encoded><![CDATA[<h4><a href="http://www.rssweather.com/hw3.php?place=paris&amp;state=&amp;country=fr&amp;utm_source=rss&amp;utm_medium=rss" title="Paris, FRANCE Weather weather forecast"><img src="http://www.rssweather.net/images/fcicons/fair.gif" alt="fair" class="icon" width="55" height="58" id="fair.gif" border="0"/></a><span class="sky">Fair</span> <span class="temp">25&#176;C</span></h4><dl style="display: inline;"> <dt style="display: inline; font-weight: bold;">Humidity:</dt><dd id="humidity" style="display: inline;">50%</dd> <dt style="display: inline; font-weight: bold;">Wind Speed:</dt><dd id="windspeed" style="display: inline;">11 KMH</dd> <dt style="display: inline; font-weight: bold;">Wind Direction:</dt><dd id="winddir" style="display: inline;">W (280&#176;)</dd> <dt style="display: inline; font-weight: bold;">Barometer:</dt><dd id="pressure" style="display: inline;"> 1015 mb</dd> <dt style="display: inline; font-weight: bold;">Dewpoint:</dt><dd id="dewpoint" style="display: inline;">14&#176;C</dd> <dt style="display: inline; font-weight: bold;">Heat Index:</dt><dd id="heatindex" style="display: inline;">26&#176;C</dd> <dt style="display: inline; font-weight: bold;">Wind Chill:</dt><dd id="windchill" style="display: inline;">25&#176;C</dd> <dt style="display: inline; font-weight: bold;">Visibility:</dt><dd id="visibility" style="display: inline;">11 km</dd></dl>]]></content:encoded><guid isPermaLink="false">C-1000 GMT+1 THU JUL 25 2013</guid></item></channel></rss>

AttributeError: 'NoneType' object has no attribute 'replace'

Hi!
I just tried to format this code below, but I receive an error. I just work with C# otherwise I will try to just place the solution in here. Thanks in advance.
Maybe could the be accentuation?

Error msg:

    Traceback (most recent call last):
  File ".\sublime_plugin.py", line 362, in run_
  File ".\indentxml.py", line 44, in run
  File ".\indentxml.py", line 96, in indent
xml.parsers.expat.ExpatError: syntax error: line 1, column 0

text to Format:

<Requisicoes><Requisicao Chave="0c136047-ce55-4bd6-9aad-6b42fde53a3a" Uri="https://www.soc.com.br/WSSoc/services/LicencaMedicaWs" DataHora="10:30:41.796"><Envio><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" /></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><consultarLoteLicencasMedicas xmlns="http://services.soc.age.com/"><consultaAfastamento xmlns=""><abonado>false</abonado><codigoEmpresaFuncionario>297044</codigoEmpresaFuncionario><dataFicha>17/09/2014</dataFicha><dataFimAfastamento>31/12/9999</dataFimAfastamento><dataInicioAfastamento>01/01/0001</dataInicioAfastamento><identificacaoVo>DADOS REMOVIDOS</identificacaoVo></consultaAfastamento></consultarLoteLicencasMedicas></s:Body></s:Envelope></Envio></Requisicao>
<Requisicao Chave="0c136047-ce55-4bd6-9aad-6b42fde53a3a" DataHora="10:30:42.270" TempoGasto="00:00:00.7448938"><Resposta><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" /><soap:Body><ns2:consultarLoteLicencasMedicasResponse xmlns:ns2="http://services.soc.age.com/"><Afastamento><abonado>true</abonado><acidenteTrajeto>false</acidenteTrajeto><cids>B00</cids><codigoEmpresaFuncionario>297044</codigoEmpresaFuncionario><codigoFuncionario>2</codigoFuncionario><codigoMotivoAfastamento>2</codigoMotivoAfastamento><codigoSequencialLicenca>53938015</codigoSequencialLicenca><cpfFuncionario>44218387729</cpfFuncionario><dataFicha>02/10/2015</dataFicha><dataFimAfastamento>19/10/2015</dataFimAfastamento><dataInicioAfastamento>02/10/2015</dataInicioAfastamento><descricaoMotivo>SUP. 15 DIAS.</descricaoMotivo><imprimirCid>false</imprimirCid><imprimirMotivo>false</imprimirMotivo><imprimirSolicitante>false</imprimirSolicitante><matriculaFuncionario>7778</matriculaFuncionario><tipoCid>DOENCA_RELACIONADOA_AO_TRABALHO</tipoCid><tipoDeAfastamento>2</tipoDeAfastamento></Afastamento><Afastamento><abonado>true</abonado><acidenteTrajeto>false</acidenteTrajeto><codigoEmpresaFuncionario>297044</codigoEmpresaFuncionario><codigoFuncionario>4</codigoFuncionario><codigoMotivoAfastamento>42</codigoMotivoAfastamento><codigoSequencialLicenca>53938296</codigoSequencialLicenca><cpfFuncionario>02374451747</cpfFuncionario><dataFicha>15/10/2015</dataFicha><dataFimAfastamento>15/10/2015</dataFimAfastamento><dataInicioAfastamento>15/10/2015</dataInicioAfastamento><descricaoMotivo>1 DIA</descricaoMotivo><imprimirCid>false</imprimirCid><imprimirMotivo>false</imprimirMotivo><imprimirSolicitante>false</imprimirSolicitante><matriculaFuncionario>7780</matriculaFuncionario><tipoDeAfastamento>7</tipoDeAfastamento></Afastamento><Afastamento><abonado>true</abonado><acidenteTrajeto>false</acidenteTrajeto><cids>E00</cids><codigoEmpresaFuncionario>297044</codigoEmpresaFuncionario><codigoFuncionario>1</codigoFuncionario><codigoMotivoAfastamento>35</codigoMotivoAfastamento><codigoSequencialLicenca>53938088</codigoSequencialLicenca><cpfFuncionario>06795882721</cpfFuncionario><dataFicha>05/10/2015</dataFicha><dataFimAfastamento>07/10/2015</dataFimAfastamento><dataInicioAfastamento>05/10/2015</dataInicioAfastamento><descricaoMotivo>3 DIAS.</descricaoMotivo><imprimirCid>false</imprimirCid><imprimirMotivo>false</imprimirMotivo><imprimirSolicitante>false</imprimirSolicitante><matriculaFuncionario>7777</matriculaFuncionario><tipoCid>DOENCA_RELACIONADOA_AO_TRABALHO</tipoCid><tipoDeAfastamento>11</tipoDeAfastamento></Afastamento></ns2:consultarLoteLicencasMedicasResponse></soap:Body></soap:Envelope></Resposta></Requisicao>
<Requisicao Chave="037c2757-a0f8-4c03-a4be-6bbfbdbe6280" Uri="http://vpc-1532-20132:1008/lg.com.br/svc/ServicoDeMovimentacao" DataHora="10:38:03.243"><Envio><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">lg.com.br/svc/ServicoDeMovimentacao/CadastreAfastamento</Action><h:LGAutenticacao xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:h="lg.com.br/svc/dto"><h:TokenSessao i:nil="true" /><h:tokenusuario>DADOS REMOVIDOS</h:tokenusuario></h:LGAutenticacao><h:LGContextoAmbiente xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:h="lg.com.br/svc/dto"><h:Ambiente>0</h:Ambiente><h:EnderecoHost i:nil="true" /><h:FuncaoEmExecucao i:nil="true" /><h:IdTenantSelecionado>0</h:IdTenantSelecionado><h:NomeHost i:nil="true" /><h:NomeTenantSelecionado i:nil="true" /></h:LGContextoAmbiente></s:Header><s:Body><CadastreAfastamento xmlns="lg.com.br/svc"><DadosAfastamento xmlns:d4p1="lg.com.br/svc/dto" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><d4p1:AcidenteDeTrajeto>false</d4p1:AcidenteDeTrajeto><d4p1:CID /><d4p1:CodigoDaEmpresa>1</d4p1:CodigoDaEmpresa><d4p1:CodigoDaSituacaoDeAfastamentoDoFuncionario>42</d4p1:CodigoDaSituacaoDeAfastamentoDoFuncionario><d4p1:DataDeInicioDoAfastamento>2015-10-15T00:00:00</d4p1:DataDeInicioDoAfastamento><d4p1:DataDeRetornoDoAfastamento>2015-10-16T00:00:00</d4p1:DataDeRetornoDoAfastamento><d4p1:DiasDeAuxilioDoenca i:nil="true" /><d4p1:DoencaRelacionadaAoTrabalho>false</d4p1:DoencaRelacionadaAoTrabalho><d4p1:MatriculaDoFuncionario>7780</d4p1:MatriculaDoFuncionario><d4p1:Observacao>1 DIA</d4p1:Observacao><d4p1:TipoDeAfastamentoRAIS>OUTROS</d4p1:TipoDeAfastamentoRAIS><d4p1:CalculeDiasAuxilioDoenca>false</d4p1:CalculeDiasAuxilioDoenca></DadosAfastamento></CadastreAfastamento></s:Body></s:Envelope></Envio></Requisicao>
<Requisicao Chave="037c2757-a0f8-4c03-a4be-6bbfbdbe6280" DataHora="10:38:24.354" TempoGasto="00:00:21.1618029"><Resposta><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header /><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring xml:lang="pt-BR">The creator of this fault did not specify a Reason.</faultstring><detail><ListaDeInconsistencias xmlns="lg.com.br/svc/dto" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Inconsistencias><Inconsistencia><Mensagem>Ocorrência de afastamento ja cadastrada.</Mensagem></Inconsistencia></Inconsistencias></ListaDeInconsistencias></detail></s:Fault></s:Body></s:Envelope></Resposta></Requisicao>
</Requisicoes>

No License

This could be most-easily solved by adding a note to the readme indicatating which license the code is available under.

Encoding problem

The plugin, if encoding of file not utf-8, change text incorrect. (in line 42)
For example for windows-1251 endoding.
I found same script for guess what an encoding the file http://pypi.python.org/pypi/chardet, but may be there is same another solving.

Don't work in sublime text 2

Hello,

Thanks for best job with this plugin.

The XML have 491800 characters.

The error is this:

Traceback (most recent call last):
File ".\sublime_plugin.py", line 362, in run_
File ".\indentxml.py", line 49, in run
File ".\indentxml.py", line 96, in indent
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 491786

Regards and @goto thanks

doesn't work for other XML syntax schemes like XAML, XSL

Currently there seems to be a hard check whether the current syntax setting is "XML". If it is not the case the "Format XML" menu entry is disabled.

But there a are a lot of other syntax schemes that are XML too and where the "Format XML" still makes sense. Such as XAML (can be installed with package control) or XSL (included out of the box).

xml.parsers.expat.ExpatError: not well-formed

import socket
import sys, os
import xmltodict,json

try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "socket successfully created"
except socket.error as err:
print "socket creation failed with error %s" %(err)

port = 8000

s.connect(('127.0.0.1', port))

s.send('GET /search?c=main&q=narendra+modi&format=xml&quick=1&hasmime=1 HTTP/1.1 Host: 127.0.0.1:8000 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:20.0) Gecko/20100101 Firefox/20.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://127.0.0.1:8000/search?c=main&q=nagesh Connection: keep-alive If-Modified-Since: Thu, 05 Jun 2014 06:18:10 GMT\r\n\r\n')

data = '';
while True:
data = data + s.recv(1024)
if not s.recv(1024):break

var = data.find('\r\n\r\n')
xmldata = (data[var+4:])
result = xmltodict.parse(xmldata)
jdata = json.dumps(result)
jsonObj = json.loads(jdata)
print jsonObj['response']['result']
print '\n'

s.close()

o/p is 👎

socket successfully created
Traceback (most recent call last):
File "result.py", line 24, in
result = xmltodict.parse(xmldata)
File "/usr/local/lib/python2.6/dist-packages/xmltodict.py", line 248, in parse
parser.Parse(xml_input, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 11, column 6

xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 18628

Traceback (most recent call last):
File ".\sublime_plugin.py", line 362, in run_
File ".\indentxml.py", line 32, in run
File ".\indentxml.py", line 48, in indentxml
File ".\xml\dom\minidom.py", line 1928, in parseString
File ".\xml\dom\expatbuilder.py", line 940, in parseString
File ".\xml\dom\expatbuilder.py", line 223, in parseString
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 18628

After indenting the syntax should be set respectively

After I run the command indent_xml, the syntax of the file should automatically be set to XML by the plugin. This is already done on plugins like "SQL Beautifier".

This is a fairly simple change that greatly improves developers' performance.

CDATA support

INPUT

<a><content><![CDATA[xxx]]></content></a>

OUTPUT

<a>
    <content>
<![CDATA[xxx]]> </content>
</a>

EXPECTED

<a>
    <content>
        <![CDATA[xxx]]>
    </content>
</a>

Strange New Lines in Sublime Text 3

I got an xml that contains elements like this:
<version>
1
</version>

I expect them to be converted to
<version>1</version>

like in V2 but it results in
<version>1
</version>

Not sure if i missed some config here.

MAC KeyMap typo

Hi, Mac KeyMap is missing an underscore, should be:
{ "keys": ["super+k", "super+f"], "command": "indent_xml" }

Thanks for the great package!

Indenting a whole doc remove <?xml?> tag

Hi Alex

Just noticed a new thing.
If I use the command on a whole doc (that is w/o selecting anything), it removes the Tag at the beginning of the doc.

cheers
MrWaz

Reformatting breaks encoding

If I reformat following XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Tag><Tag1>Småhus</Tag1></Tag>

It produces

<?xml version="1.0" encoding="ISO-8859-1"?>
<Tag>
     <Tag1>Småhus</Tag1>
</Tag>

Keyboard shortcuts doesn't work on Linux

I've found that when switching between a Windows and Linux machines to keyboard shortcuts, doesn't work on Linux. If I edit the Linux shortcuts file to reflect the Windows file it works.

Removes newlines

Thanks for the plugin! I have an Ant build file that has carefully placed newlines to separate sections of property declarations, targets, etc. When I run this it removes all the newlines and every section gets bunched up with the others. Is there an option to prevent it from doing so?

The menu command should be enabled for all syntaxes

The menu command is disabled, and thus the shortcut does not work either, unless the syntax is set to XML.

Many times one will be writing HTML as XHTML (all ebook producers, for instance) it would be handy to have the command available for HTML too. Sometimes XML will be embedded inside a file written in another language, and the running command only on the selection is useful too.

My take would actually be not trying to outsmart the user, and have the command available always, letting the user decide wether his selection is in an appropriate language that Indent XML will understand or not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.