![]() ![]() Displaying XML Files Using CSSIf you’ve ever tried to open an XML file and expected to view it like a typical HTML file, chances are you were disappointed with the results. When you clicked that XML file open, you probably saw something like this (sample code taken from the W3. C): < ? xml version="1. ISO- 8. 85. 9- 1"?> < CATALOG> < CD> < TITLE> Empire Burlesque< /TITLE> < ARTIST> Bob Dylan< /ARTIST> < COUNTRY> USA< /COUNTRY> < COMPANY> Columbia< /COMPANY> < PRICE> 1. PRICE> < YEAR> 1. ![]() By Darla Ferrara. One question that comes up often is ‘How Do I Display XML on a Web Page?’ If you are familiar with CSS files for HTML, you will appreciate the. YEAR> < /CD> < CD> < TITLE> Hide your heart< /TITLE> < ARTIST> Bonnie Tyler< /ARTIST> < COUNTRY> UK< /COUNTRY> < COMPANY> CBS Records< /COMPANY> < PRICE> 9. PRICE> < YEAR> 1. YEAR> < /CD> That type of layout does you no good. When XML data contains HTML tags. How To Display HTML in XSL Style Sheet. Here is the XML file that we want to display. . Creating a Web Page to Display XML Data. which allows you to specify which level of the XML data file you want to extract. from the HTML group. To display XML data inside an HTML page you can use JavaScript to. Displaying XML with. prepared by the server and returned to the browser as an HTML file. ![]()
You can read it, sure, but you’d have a very hard time making sense of an entire report by reading it in this manner. XML files do not carry any formatting information, therefore, you simply see a raw output. The W3. C recommends formatting an XML file either with CSS, XSLT or even Java. Script. If you use CSS, it’s as simple as (from the W3. C): CATALOG{background- color: #ffffff; width: 1. CD{display: block; margin- bottom: 3. TITLE{color: #FF0. ARTIST{color: #0. FF; font- size: 2. COUNTRY,PRICE,YEAR,COMPANY{display: block; color: #0. To link the XML file to the CSS, you use this code: < ? But let’s say you have an extremely complex XML file that doesn’t fit the traditional CSS formatting method. An excellent example of this are Amazon Associates reports. Amazon allows their Associates to download reports as either TSV or XML files. If you download the XML file, your best bet for viewing this report is by opening it in Microsoft Excel. To do so, start with Excel open, then from the File menu click Open, navigate to the XML report, click it, and then choose to open ‘As an XML table.’ Excel will then notify you that the file does not refer to a schema and will create one for you. Click OK and you’ve got yourself a readable report. It’s still not perfect, but at least you can read it. According the to the W3. ![]() C, XSLT (e. Xtensible Stylesheet Language Transformations) is the preferred method for formatting XML because it is far more sophisticated than CSS. XSLT can transform XML into HTML before it is displayed by a browser. Here is some example XML code from the W3. C that will be formatted through XSLT: < ? ISO- 8. 85. 9- 1"?> < !- - Edited by XMLSpy® - -> < breakfast_menu> < food> < name> Belgian Waffles< /name> < price> $5. Belgian Waffles with plenty of real maple syrup< /description> < calories> 6. ISO- 8. 85. 9- 1"?> < !- - Edited by XMLSpy® - -> < html xsl: version="1. XSL/Transform" xmlns="http: //www. Arial; font- size: 1. EEEEEE"> < xsl: for- each select="breakfast_menu/food"> < div style="background- color: teal; color: white; padding: 4px"> < span style="font- weight: bold"> < xsl: value- of select="name"/> < /span> - < xsl: value- of select="price"/> < /div> < div style="margin- left: 2. The W3. C provides an excellent testing tool here. In many regards, XML is now considered old news in that it never really caught on as a completely mainstream means to deliver content to the web. However, if you’re like me and need to read Amazon Associates reports, then knowing how to open the XML file in Excel becomes crucial. It’s also good to know that you can format basic XML files in CSS.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
October 2016
Categories |