|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Tool for formatting XML
Does anyone know of a useful tool for formatting XML? I frequently get XML files with a mixture of hard tabs and spaces, and they're difficult to read.
What I'd really like is some type of command line utility that would generalize the whitespace characters, and format the XML nicely. I looked on Sourceforge, but no luck. -Antun |
|
#2
|
|||
|
|||
|
You can try HTML Tidy: http://tidy.sourceforge.net/ It supports XML. Since you're just wanting formatting http://sourceforge.net/projects/htmltrim might suit your needs.
|
|
#3
|
|||
|
|||
|
Thanks - HTMLTidy worked out really nicely. I would rather have had a command line script, but it does just what I want.
-Antun |
|
#4
|
|||
|
|||
|
Umm, Tidy is a command line program.
![]() |
|
#5
|
|||
|
|||
|
D'oh! I meant htmltrim. I'll have a look at HTMLTidy. What impressed me the most about htmltrim was that it could wrap attributes and align them to the left hand margin of the first attribute.
-Antun |
|
#6
|
|||
|
|||
|
Ah.
![]() Well, if command line is important to you then you should probably take a look at Tidy. I think HtmlTrim uses tidy to do the work, it just wraps tidy in a gui and presents a more focused set of options. |
|
#7
|
|||
|
|||
|
I've played with HTMLTidy a little, and it's exactly what I've been looking for. The only thing I can't figure out is how to prevent it from stripping line breaks (I'm using the xml option).
My code frequently has things like this: Code:
<method event="onclick">
this.datapath.deleteNode();
this.datapath.selectPrev();
</method>
The problem is that HTMLTidy outputs this: Code:
<method event="onclick">this.datapath.deleteNode();
yhis.datapath.selectPrev();</method>
Here are the settings I use in my config file: Code:
wrap: 66 input-xml: yes output-xml: yes indent: yes indent-spaces: 4 indent-attributes: yes tab-size: 4 literal-attributes: yes I've tried adding: Code:
new-pre-tags: method ... but it then doesn't indent the closing <method> tag at all (it looks like this): Code:
<method event="onclick">
this.datapath.deleteNode();
yhis.datapath.selectPrev();
</method>
Any ideas? -Antun |
|
#8
|
|||
|
|||
|
I think what you want it to make <method> a CDATA tag, but it doesn't look like that's supported yet. Try adding "add-xml-space: yes" to your config and see if it changes anything.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Tool for formatting XML |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|