We help IT Professionals succeed at work.

Pretty print xml

jazzIIIlove
jazzIIIlove asked
on
Hi,

I have a long xml stg like:
<block1>gj</block1><block2>fhh</block2>..,

Open in new window


The nodes names varies, there are children. All i need to do is pretty print it, like indenting.

I know i can pretty print with notepad++ but the gist is not opening it but supplying the xml file to a simple cmd exe.

Any open source light exe?

Br
Comment
Watch Question

Distinguished Expert 2019

Commented:
xml doesn't care about looking nice it is simply data. programs that consume xml also don't care about nice formatting it is between the <> and the </> that is important
Hi,

I am asking this question for readability of a file perspective.
Essentially notepad++ has the functionality to pretty print. I practically need stg that does do the same but without opening up the file in an editor.

Br
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
You need something to display it, so in essence you either have a text console -- not very useful --, or an editor. If the XML string does not contain many nodes, the console output might be ok.
One way is using PowerShell and the PowerShell Community Extensions (https://pscx.codeplex.com/), which import a format-xml cmdlet:
get-content c:\file.xml | format-xml

Open in new window

Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
If you prefer Java ...
Hi,

Even i want to use, i don't know how to use Xalan.

Also, my xml is complex. Can i still use your solution?
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
If your XML is complex, I cannot see why you are not wanting to use an editor like Notepad++ or MS XML Notepad. But you can still use a console output approach as my suggestion, it will just not be very informative ;-).