XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 28th, 2004, 12:08 PM
karlovac karlovac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 40 karlovac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
  #2  
Old January 28th, 2004, 01:58 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
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.

Reply With Quote
  #3  
Old January 31st, 2004, 10:12 PM
karlovac karlovac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 40 karlovac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Thanks - HTMLTidy worked out really nicely. I would rather have had a command line script, but it does just what I want.

-Antun

Reply With Quote
  #4  
Old February 1st, 2004, 03:38 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Umm, Tidy is a command line program.

Reply With Quote
  #5  
Old February 1st, 2004, 06:50 PM
karlovac karlovac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 40 karlovac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
  #6  
Old February 2nd, 2004, 12:52 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
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.

Reply With Quote
  #7  
Old February 6th, 2004, 11:55 AM
karlovac karlovac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 40 karlovac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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

Reply With Quote
  #8  
Old February 6th, 2004, 07:08 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Tool for formatting XML


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT