Results 1 to 4 of 4

Thread: Display Contents of XML File

  1. #1
    Join Date
    Jan 2009
    Posts
    46

    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

  2. #2
    Join Date
    Dec 2008
    Posts
    322

    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.

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Display Contents of XML File

    shows a simple XML file for demonstration

    <?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.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Display Contents of XML File

    it is just an extract from the DisplayCatalog() method of the C# application.
    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();

Similar Threads

  1. Regular Expressions on the Contents of a File
    By samualres in forum Software Development
    Replies: 4
    Last Post: 19-02-2010, 10:30 PM
  2. Windows 7 search does not return file contents
    By Benedict in forum Operating Systems
    Replies: 3
    Last Post: 05-12-2009, 10:38 AM
  3. file maker to display the contents of last record
    By Bigga Lexx in forum Windows Software
    Replies: 3
    Last Post: 09-09-2009, 03:26 PM
  4. Replies: 3
    Last Post: 23-07-2009, 09:31 PM
  5. How to import txt file contents into lists in python
    By Jasonholt in forum Software Development
    Replies: 3
    Last Post: 16-05-2009, 06:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,486,874.60133 seconds with 16 queries