idarkstranger (idarkstranger) wrote in macosxdev,

NSXMLDocument how i can format ?

i have some XML document and i want formatted his

this source xml !

i want save source xml and see in my xml file )))

  • Post a new comment


    default userpic

    Your IP address will be recorded 

  • 1 comment


January 10 2011, 13:15:56 UTC 3 years ago

This will get you close to what you're looking for. In Terminal, use the command xmllint with the --format option. When I tried, it added an xml declaration to the top of the code (which you can later delete if you really don't want to keep it, but you probably want it anyway). It also collapsed the third element to be self-closing instead of having a an opening and closing tag.

E.g., here's what it looks like to me:

$ cat tmp.xml 

$ xmllint --format tmp.xml 
<?xml version="1.0"?>

That just displays the output. If you want to save it, you need to redirect the output to a new file:

$ xmllint --format tmp.xml > new.xml

There are also probably text editors, etc. that have options to reformat XML in place, but this is an easy way to use the command-line to do it.