Need asp help

Status
Not open for further replies.

dormahc

Wise, Aged Ars Veteran
129
I'm building a section of a website with asp and xml, and I have it set up so that the asp calls to the xml doc and writes the text to the browser. I need to set it up so that the asp can write a
tag whenever it encounters a return in the text. example:

**** "poem.xml" XML Doc****

<document>
<content>
<![CDATA[

Smell the buring flesh.

Taste the tangy sulphur air.

Volcano season.

]]>
</content>
</document>

****XML Doc****

====Asp page====

<%

Set objXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load(Server.MapPath("poem.xml"))

%>

<html>
<title>Haiku</title>
<body>

<%

poemString = objXMLDoc.firstChild.firstChild.text

%>
<%=poemString%>

</body>
</html>

====Asp page====

Right now, this will right the folowing in the browser:

Smell the buring flesh.Taste the tangy sulphur air.Volcano season.

How do I get it to write the following without adding
tags in the XML doc :confused: :

Smell the buring flesh.

Taste the tangy sulphur air.

Volcano season.
 

TheJet

Ars Praefectus
4,598
Subscriptor++
Does this work?

code:<HR>
Code:
poemString = Replace(objXMLDoc.firstChild.firstChild.text, vbCrLf, "
")

or maybe:

code:<HR>
Code:
<div style="whitespace: pre">
<%=sPoemString%>
</div>

Can't remember the exact whitespace css modifier, so it might also be "whitespace: preserve" or something like that, I don't have time to look it up at the moment. The first solution should work in all browsers (since the replace happens on the server), the other should work for browsers which support the "whitespace" css attribute.

TheJet
 

Aeirould

Ars Tribunus Angusticlavius
7,535
Subscriptor
Why not:

code:<HR>
Code:
<%
Set objXMLDoc = Server.CreateObject("Microsoft.XMLDOM") 
objXMLDoc.async = False
objXMLDoc.load(Server.MapPath("poem.xml"))
%>
<html>
<head><title>Haiku</title></head>
<body>
    <pre>
    <%=objXMLDoc.firstChild.firstChild.text%>
</body>
</html>
</pre>

That should work fine in all browsers (assuming the msXMLDOM object passes the CDATA out correctly, of course)?

If you insist on not using the
Code:
 tag, you could combine the above two by doing:<P><BLOCKQUOTE><font size="-1">code:</font><HR><pre>
<%
Set objXMLDoc = Server.CreateObject("Microsoft.XMLDOM") 
objXMLDoc.async = False
objXMLDoc.load(Server.MapPath("poem.xml"))
%>
<html>
<head><title>Haiku</title></head>
<body>
    <%=Replace(objXMLDoc.firstChild.firstChild.text,vbCrLf,"
")%>
</body>
</html>
<HR></BLOCKQUOTE>
 

dormahc

Wise, Aged Ars Veteran
129
after some experimenting I found that the css "white-space: pre" did not work at all. the Replace function didn't seem to do what I was lookin for either. The <pre> tag worked best, but isn't quite there.

Yes, it copies the whitespace pretty well, but its too good at what it does. The text will not auto wrap, which is causing the table the text is housed in to kick out somethin fierce. I tried to set the table and cell width to get it to wrap, but no dice. This leaves it to me to go and manually wrap the text the way it should. Any suggestions for a work around to this?
 
Status
Not open for further replies.