Display Contents of XML File
I have little to no experience with XML, and the only real experience I have with XML is creating XML with PHP from a db, so do not really know where to start with displaying and formatting this content.Is it possible to format XML in an xhtml doc, whilst maintaining all the other xhtml page elements.some one can explain how to display content of XML file.
thank you
Re: Display Contents of XML File
there are some thing you need to know:
1) not every browser are able to transform xml+xsl natively. To support everyone, you must have an xslt engine on the server to do the transformation and serve html to the client
2) javascript that use document.write() or div.innerHTML are not going to work. I think this is related to the browsers, but at least, in forefox, they will somply not work.
3) if you embed javascript or html in the xml, they will need to be escaped to not interfer with the xml markup. And you will need to use CDATA sections to present them correctly.
Re: Display Contents of XML File
shows a simple XML file for demonstration
Quote:
<?xml version="1.0"?>
<Books>
<Book ID="001">
<Author>Mark</Author>
<Publisher>Sams</Publisher>
</Book>
<Book ID="002">
<Author>Joe</Author>
<Publisher>AWL</Publisher>
</Book>
</Books>
To test the above XML file for errors, simply open it with your browser. If it has no errors, the file will be displayed as such.
Re: Display Contents of XML File
it is just an extract from the DisplayCatalog() method of the C# application.
Quote:
display all the data using a C# console application
XmlNodeList xmlnode = xmldoc.GetElementsByTagName("Book");
Console.WriteLine("Here is the list of catalogs\n\n");
for(int i=0;i<xmlnode.Count;i++)
{
XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;
//XML Attribute Name and Value returned
//Example: <Book id = "001">
Console.Write(xmlattrc[0].Name);
Console.WriteLine(":\t"+xmlattrc[0].Value);
//First Child of the XML file - Catalog.xml - returned
//Example: <Author>Mark</Author>
Console.Write(xmlnode[i].FirstChild.Name);
Console.WriteLine(":\t"+xmlnode[i].FirstChild.InnerText);
//Last Child of the XML file - Catalog.xml - returned
//Example: <Publisher>Sams</Publisher>
Console.Write(xmlnode[i].LastChild.Name);
Console.WriteLine(":\t"+xmlnode[i].LastChild.InnerText);
Console.WriteLine();