Pretty print xml

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
LVL 12
jazzIIIloveAsked:
Who is Participating?
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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

0
 
David Johnson, CD, MVPOwnerCommented:
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
0
 
jazzIIIloveAuthor Commented:
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
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
jazzIIIloveAuthor Commented:
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
If you prefer Java ...
0
 
jazzIIIloveAuthor Commented:
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?
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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 ;-).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.