Jump to content

Tabs And Newlines


jeffman

Recommended Posts

So I'm working with XML now. The idea is that user input generates an XML doc in the browser, then the browser sends it to the server via AJAX, and the server saves it as a file. The file can be retrieved via AJAX for editing, and simpleXML can parse it for basic reports. It's a very tidy system. FWIW, XSL is not a factor.When I started developing, I used existing XML docs with all the tabs and returns you expect for human readability, and that looked normal to me, and I figured I'd just stick with that.When I created the editing routines, I found that XML DOM methods have no respect for white space in parent elements. The results are ugly. Maybe you've seen this. I am not aware of XML Object methods that reformat. (Maybe I missed something?)On the other hand, browsers and PHP don't care about tabs and returns.So now I'm thinking I'll just leave them out. My routines get streamlined, and I can cut back a little transmission time. (Though at most I'm talking a 500-1000 chars per file, so it's not a big deal.)In a plain text editor, files produced this way are not exactly human-readable (which spoils a traditional reason for choosing XML).But even the dumbest real editor restores the tabs and returns, so human-readability is not a serious concern.And I don't expect humans to read these documents except in emergencies.Should I worry about not having tabs and returns? Am I overthinking this? Or is there a bump down the road I'm not aware of?

Link to comment
Share on other sites

Well, there's the xml:space="preserve" attribute. You can specify that on any element, and all whitespace inside will be preserved in the DOM.Be careful with it though, as it means you'll have to "manually" perform whitespace normalization inside when you need it.Example:

<root>	<el1 xml:space="preserve">This issometext with whitespace</el1>	<el2>This issometext with whitespace</el2></root>

The nodeValue of el1 is

This issometext with whitespace

and the nodeValue of el2 is

This is some text with whitespace

Also, I'm not completely sure how far browser support for this goes. Also, some editors also don't support it (in that if you "pretty print" the code, they'll format these elements, thereby potentially disturbing their semantics), though most do respect it. I know libxml (and therefore PHP) supports it...

Link to comment
Share on other sites

Thanks for digging this thread up. I've just Googled that attribute. In explaining it, one author gave me the impression it exists because the white space I was talking about really isn't significant. So I think my initial question is answered. (Ie, I shouldn't worry.)I also get the impression that xml:space should be reserved for content where the space really is semantic, as in poetry and such. "pretty print" space seems to have no semantic value, so I'd probably be abusing the attribute if I used it to preserve that.It's a good thing to know about, though, and I suspect I'll need it sooner than later. I probably could have found it in a manual, but I've hesitated to buy one because they seem have a lot more information than I need at this moment. I'm focused totally on data storage/transmission right now, and the books spend a lot of time on style and transformations, and I don't need that yet. But I may have to bite the bullet . . .Then again, what usually happens with me is, I read about something just to learn about it, and then I realize I can put it to use. That's how I got interested in XML in the first place.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...