Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Putting XML data in a XHTML page

Status
Not open for further replies.

gohankid77

Technical User
Jun 28, 2004
65
US
Incoming Newbie to the site!

Note: My page is valid if I don't use the <xml> tag or the datasrc and datafld attributes.

In the past, I have used the <xml> tag, which is not supported by the W3C, to add data from an XML file into my HTML page. However, I recently came upon the W3C's validation service. My page is not valid. Is there a way for me to add XML to my XHTML page and make it valid without using a substantial amount of coding in JavaScript or another scripting language? I was thinking the <link> tag would work, but I have no idea how I would use it or what values I would use for the attributes. Here is a test page in XHTML 1.1 code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "<html>
<head>
<title>Test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
th
{
text-align: left
}
-->
</style>
</head>
<body>
<!-- I know the XML tag is not a tag supported by the W3C -->
<xml id="test" src="test.xml"></xml>
<table style="border-width: 0px" datasrc="#test">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td><span datafld="abc"></span></td>
<td><span datafld="def"></span></td>
<td><span datafld="ghi"></span></td>
</tr>
</table>
</body>
</html>

And here is my test.xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<test>
<abc>ABC</abc>
<def>DEF</def>
<ghi>GHI</ghi>
</test>

If you have any ideas about this. Please let me know.
 
Based on the messages returned by the Validator service, it tells you that the DTD (Document Type Definition) doesn't support the XML tag, nor the attributes of this tag (as well as some other attributes you have added to SPAN and TABLE tags).

You would need to create your own XHTML 1.1 DTD which includes these tags/attributes before it will parse and validate correctly.

Hope this helps.

Pete.


Web Developer & Aptrix / IBM Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
To get your data into the document, I'd suggest using some sort of server side code (PHP, ASP, etc). They you could write the code directly to the page, as it is being served out. No need for JavaScript, no need for separate page requests (reducing download times), and by removing the "src" attributes, you would have a valid XHTML document.

Hope this helps.

Pete.


Web Developer & Aptrix / IBM Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
If you're happy with the end results, it doesn't really matter whether the page validates or not.

What the failure to validate should make clear, though, is that not all browsers will know how to treat the <xml> tag - which will radically mess up your page for some of your visitors.

So, if you're working on an intranet and have control over the browsers used to visit the page, you can (probably) get away with this code. If you're working over the internet, then you should really be looking at server-side techniques to ensure that end-users only receive valid, standard HTML.

-- Chris Hunt
 
Does your "xml" element simply embed an XML document in your HTML document? If so, the valid way to do that is with an OBJECT element.

<object data="foo.xml" type="application/xml"/>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top