I am having a PHP script that generates the xml using the data in a mysql database. We have "nl2br" function in PHP that preserves the format (<br /> <p> etc..). When i use this method to generate the xml, the xml file that gets generated contains the <br /> tag in the node tree. Is there any other way to preserve the format even in the generated xml, without having the <br /> tags.
generated xml:
<category>
<threads>
<threadDetails>"I typically use this column to look at future trends."
<br />
"I typically use this column to look at future trends."</threadDetails>
</threads>
</category>
Javascript statement that places the nodevalue:
var threadDetails = result.getElementsByTagName("threadDetails")[i].firstChild.nodeValue;
document.getElementById("thread").innerHTML = threadDetails;
html:
<div id="thread">"I typically use this column to look at future trends."</div>
expected html:
<div id="thread">
"I typically use this column to look at future trends."
"I typically use this column to look at future trends."
</div>
<br /> tag is added by the php script generating the xml. Basically what i am trying to do is to fetch and display the two paragraphs stored in the database. Please tell me how to make the xml parser to display two seperate lines as two seperate lines instead of one.
ex:
<?xml version="1.0" encoding="utf-8" ?>
<category>
<thread>
"This is first line..."
"This is second line..."
</thread>
</category>
if i use javascript to read this xml and display the output, the output shuld read
"This is first line..."
"This is second line..."
not
"This is first line...""This is second line..."
please do help me out,
thanks,
tannu
Last edited by tannu; 06-26-2007 at 02:51 PM..
Reason: was not complete
dynamically generated xml is (thru php, using data stored in mysql, two parargraphs that read:"I typically use this column to look at future trends.")
<category>
<threads>
<threadDetails>"I typically use this column to look at future trends."
<br />
"I typically use this column to look at future trends."</threadDetails>
</threads>
</category>
I am using DOM to generate the div and related elements and appending the related result. Following is the snippet:
xmlhttp_categoryThreads is XMLHTTPRequest object
result = result = xmlhttp_categoryThreads.responseXML;
var threadDetails = result.getElementsByTagName("threadDetails")[i].firstChild.nodeValue;
var p_threadDetails = document.createElement("p");
var txt_threadDetails = document.createTextNode(threadDetails);
p_threadDetails.appendChild(txt_threadDetails);
div_categoryThread.appendChild(p_threadDetails);
intended o/p is:
<div id="div_categoryThread">
"I typically use this column to look at future trends."
"I typically use this column to look at future trends."
</div>
o/p i am getting:
<div id="div_categoryThread">
"I typically use this column to look at future trends."
</div>
the problem, what i think may be the <br /> tag that the XML is having,
is there any way to generate the xml having the same format as the data fetched by the database?
the data stored in the mysql:
"I typically use this column to look at future trends."
"I typically use this column to look at future trends."
I am using the nl2br formatting function in php, which basically preservs the format, in this case a <br /> tag.
please tell me where i am going wrong, and suggest any other alternative to achieve the desired result.
Remember for small data sets with ajax you do not have to use XML at all. I programmed an ajax site using PHP and just used comma delimited data strings so I could parse them easily back in the client with JS. XML wasn't needed at all to pass the data back to the client thru the "ajax tunnel".