Relegence
asked on
Trying to indent XML data within a div
Hello,
I have a long XML string which I put in a <div> (in a <xmp> tag) the following way:
<div>
<xmp><%= xmlStr%></xmp>
</div>
(xmlStr is taken from the server side)
The string looks like XML but it appears as 1 long row with no indentation.
How can I make it look like a XML with indentation?
Thanks...
I have a long XML string which I put in a <div> (in a <xmp> tag) the following way:
<div>
<xmp><%= xmlStr%></xmp>
</div>
(xmlStr is taken from the server side)
The string looks like XML but it appears as 1 long row with no indentation.
How can I make it look like a XML with indentation?
Thanks...
The browser will not format XML text just because it is XML text. It thinks it is just a stream of characters--nothing more. You would have to do some magic to make the browser treat the text as an XML stream. I don't specifically know of a way to achieve that effect, so let me think about this.
ASKER
Thank you both - the first suggestion is not good for me since I don't know the XML format in advance.
Maybe I can achieve what I need in a different way - I have a XML string in the server side and I want to put it within a div and show it as a XML document.
Maybe I can achieve what I need in a different way - I have a XML string in the server side and I want to put it within a div and show it as a XML document.
Well, another way would be to use XSLT to transform the XML to HTML so that you can display it in the browser, but generic XSLT is pretty difficult.
Another way would be to use an iframe that points to an .aspx file that adds the XML file to the response stream:
<iframe src="XmlReader.aspx">
</iframe>
XmlReader.aspx:
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/xml";
Response.WriteFile(Server. MapPath("T est.xml")) ;
Response.End();
}
Another way would be to use an iframe that points to an .aspx file that adds the XML file to the response stream:
<iframe src="XmlReader.aspx">
</iframe>
XmlReader.aspx:
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/xml";
Response.WriteFile(Server.
Response.End();
}
ASKER
The second suggestion which sounds better is problematic because I don't have a XML
file. I only have a very long XML string....
file. I only have a very long XML string....
Where does the XML come from?
ASKER
It comes from a servlet. I call a url with some parameters and get the XML in return
Can you show me how that is done?
ASKER
Sorry for the delay..... Here it is:
The 'resp' is a XML string so I try to show it formatted as XML.
I put it in a <div> but it is not formatted...
The 'resp' is a XML string so I try to show it formatted as XML.
I put it in a <div> but it is not formatted...
HttpWebRequest weR = (HttpWebRequest)HttpWebRequest.Create(theURL);
webRes = (HttpWebResponse)weR.GetResponse();
string resp;
using (StreamReader sr = new StreamReader(webRes.GetResponseStream()))
{
resp = sr.ReadToEnd();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For example, if your structure was
<root>
<person>
<age />
</person>
<person>
<age />
</person>
</root>
You could use:
xmlStr.Replace("<person
Notice that that adds a <br /> at the beginning of each line, knocking it down one line, and adds how many spaces in relation to what the element is.