Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-07-2007, 08:54 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,503
sde is on a distinguished road
XML 1.0 Line Feed / New Line

are new line characters compliant with XML 1.0 or should I be using a special character?

for example:
Code:
<notes>
  <item>here
is a note with
multiple lines</item>
</notes>
__________________
Mike
sde is offline   Reply With Quote
Old 02-07-2007, 02:28 PM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 701
DJMaze is on a distinguished road
depends on the purpose.

Either use:
- CR+LF (windows)
- LF (linux).
- wrap all data inside <![CDATA[ DATA HERE ]]>
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 02-07-2007, 04:17 PM   #3 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
You are allowed to use any character that is valid in your declared encoding. The parser is supposed to be able to handle character encodings properly.

Whether you should be using a special tag depends on the semantics of the XML language you are targetting and should be defined by that standard. The xhtml xml language states that whitespace in the actual text nodes will be ignored and asks that you use 'br' tags instead. My homebrew XML frame delivery specification on the other hand uses literal unix-style newline characters in the text nodes. It all depends really.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 02-08-2007, 05:34 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,503
sde is on a distinguished road
the problem stemmed from an ajax app which wasn't sending new lines properly. i have found that the problem isn't in the XML, but the javascript below it.

it is kind of interesting though. let's say i have a textarea named/id "foo". in the textarea, i have multiple lines.

var msg = document.getElementById('foo').value;

msg now contains the literal characters \n where there is a new line. when that gets sent into our framework, the backslash was somehow getting taken out.

i ended up replacing \n with the hex line feed character and everything was fine.

msg.replace(/\n/g,"%0A");

we don't have this problem when the text field is submitted over a POST request (in other areas of the app) and then sent through the same API over PHP.

if that doesn't make sense, we have a framework that supports the same API calls from either AJAX or PHP requests.

anyway, problem is solved. thanks for the info.
__________________
Mike
sde is offline   Reply With Quote
Old 02-08-2007, 07:00 AM   #5 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Maybe the AJAX framework expects all strings to be passed through encode() before being sent?
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 02-08-2007, 07:06 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,503
sde is on a distinguished road
after more testing this morning i found that (my previous post) was not the solution. i needed to escape the first backslash of the \n.. so replacing \n with \\n did the trick.

the guy who wrote the framework is on vacation and i don't feel like an in-depth investigation right now
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding XML j.gohel HTML, XML, Javascript, AJAX 2 08-21-2006 05:24 PM
How to re-organized XML file and call XML file from my software bella_11041988 HTML, XML, Javascript, AJAX 10 05-16-2006 09:03 PM
cgi script Henry PHP 25 12-30-2002 06:54 AM


All times are GMT -8. The time now is 05:23 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting