Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-10-2012, 07:17 PM   PM User | #1
Alex Vincent
Moderator


 
Join Date: May 2002
Location: Hayward, CA
Posts: 1,427
Thanks: 1
Thanked 19 Times in 17 Posts
Alex Vincent is on a distinguished road
Post Insignificant whitespace and formatting markup

Hey, folks. I'm working on some JavaScript code to parse a XML document into a Document Object Model (DOM) and later reserialize it with the user's changes. The catch is I want to try to preserve the document's existing whitespace format, so as not to interfere with SVN diff/blame or Mercurial diff/blame.

At first you might think, "well, whitespace is just a text node, and that's always significant." There are two problems with this. First, in many languages whitespace isn't that significant (XHTML, MathML, SVG, RDF, etc.) - browsers could care less. Second, there's whitespace which isn't part of a DOM node: the spacing between attributes. Case in point:

Code:
<author firstName="Isaac" lastName="Asimov" title="Dr."/>
versus

Code:
<author firstName="Isaac"
        lastName="Asimov"
        title="Dr."/>
Few XMLSerializer's will care about that, but it's a source of pain when dealing with revision control.

Does anyone know of any algorithms or existing API's for dealing with this adequately? I'm likely to write my own, but I would appreciate seeing whatever others have come up with.
__________________
"The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
June 30, 2001
author, Verbosio prototype XML Editor
author, JavaScript Developer's Dictionary
https://alexvincent.us/blog
Alex Vincent is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:45 AM.


Advertisement
Log in to turn off these ads.