0

I need to display a XML format data fetched from the database to be displayed in a division. But its not displaying with the xml tags on. Is there any way to get xml data as such with the tags in the div?

The xml which i need is given below:

<Name>public</name><Number>848065065639AuthDemoClient:STGKSITM01:20140109052539707</Number><Ret>y</Ret><Tmestamp>2014-01-09T17:22:15.318+05:30GCSD017263</timestamp>

But its getting displayed as follows:

public848065065639AuthDemoClient:STGKSITM01:20140109052539707y2014-01-09T17:22:15.318+05:30GCSD017263

Please suggest a solution

5

4 Answers 4

0

In your HTML, you can try displaying it in a textarea like below , it will display XML as it is JsFiddle Example

<div>
<textarea rows="20" cols="40" style="border:none;" disabled>
    <?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <country>Columbia</country>
        <price>10.90</price>
        <year>1985</year>
    </cd>
</catalog>
</textarea>

Sign up to request clarification or add additional context in comments.

Comments

0

Try creating a style like this

<head>
  #xml   { padding-left: 20pt; background-color: #ffffb3; color: #990000; font-size: 14px; font-family: Courier New, Lucida Sans Typewriter, Lucida Typewriter, monospace; font-weight: 600; white-space: pre; }
</head>

Then referencing in the

<textarea id=xml rows="20" cols="40" style="border:none;" disabled>

It's the 'white-space: pre' that's the important bit...

Comments

0

You can do:

xml.replaceAll("<", "&#60;")
   .replaceAll(">", "&#62;");

Comments

0

.
.
divResults.InnerHtml = XML2HTML(myResults);
.
.


public string XML2HTML(string pxmlString)
{
   return pxmlString
     .Replace("&", "&amp;")
     .Replace("<", "&lt;")
     .Replace(">", "&gt;")
     .Replace(""", "&quot;")
     .Replace("\n", "<br/>")
     .Replace("\t", " &nbsp; &nbsp; &nbsp; &nbsp;")
     .Replace(" ", " &nbsp;");
   }

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.