Jump to content

XHTML / XML, displaying inside HTML elements question


wahlers

Recommended Posts

Description:While creating XHTML web pages I try to separate the data likely to change (such as for instances addresses) from the more stable contents (such as logo's, general descriptions and the like).The idea is to separate the data that is likely to change on a regular basis from the main pages.And separate this data for ease of maintenance and and ease of updates using (coded) interfaces.This can be accomplished in several ways, of course, like storing this data in a database and use some kind of script language to built the page on the server side.But for various reasons I decided to exploit some other solution as explained in the following.

  1. Create static XHTML source.
  2. Read XML file with specific user data into this static XHTML source.
  3. Create update facilities for the user with controlled access and authorisation through the internet on these XML files (and only these files).

phase 1 is creating the static XHTML and XML files ( a + b ) .phase 2 is designing, defining and coding the access update authorisation for these specific user data (later!).I have some problems and questions about phase 1...as illustrated by the example following.Example code:The web page (simplified!), displaying an address:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>example : loading (semi-)variable data using "src=", "datasrc=" and "datafld="</title></head><body><div>  <xml src="./exampleContactAddress.xml" id="contactAddress" ></xml>  <strong> Our department: </strong>   <span datasrc="#contactAddress" datafld="department"></span>  <p><strong> Our address: </strong><br />	<span datasrc="#contactAddress" datafld="name"></span><br />	<span datasrc="#contactAddress" datafld="street"></span><br />	<span datasrc="#contactAddress" datafld="postalcode_place"></span> </p>  <p> <strong> Email: </strong>   <span datasrc="#contactAddress" datafld="mailURL"></span> </p>  <p> <strong> Phone: </strong>   <span datasrc="#contactAddress" datafld="phone"></span> </p></div></body></html>

The XML file read into the web page:(name of XML file must be as coded in the XHTML file, that is, the name must be: "exampleContactAddress.xml")

<?xml version="1.0" encoding="ISO-8859-1"?><contactAddress xmlns:xlink="http://www.w3.org/1999/xlink">	<department>ACME inc. - department A</department>	<name>John Doe</name>	<street>Capitol hill 44</street>	<postalcode_place>54321 Washington BS</postalcode_place>	<mailURL>john.doe@acme.inc.com</mailURL>	<phone>215-555-9876</phone></contactAddress>

Result (more or less!):

Our department:   ACME inc. - department AOur address: John DoeCapitol hill 4454321 Washington BSEmail:   john.doe@acme.inc.comPhone:   215-555-9876

Problem:The XHTML page does not validate! Why not?N.b. the web page does display the data of the XML file correctly in the various web browsers.What am I doing wrong?question:How do I include a mailto link in the email address?In other words, how do I make my email address, being: 'john.doe@acme.inc.com', clickable?N.b. The mailto link must be defined in the XML file and not on the web page itself.The <mailURL> tag in the XML file currently is an element containing plain text and no 'href=mailto' link. I know how to do it within the XHTML code, but the whole point is to leave all variable data, like mailto links, out of the static XHTML code. N.b. Within the XML file I have tried xlink (see following additional remarks discussing this trial).What I have done sofar:The example I gave above is a variation of my (limited!) understanding of the the W3C examples as illustrated in the following W3C link:http://www.w3schools.com/xml/tryit.asp?filename=cd_firstn.b. It infuriates me that I cannot retrieve the code example of the 'Belgian waffles' anymore of the W3C site on which I truly based my solution (see my previously mentioned code).As for the mailto link...I tried and experimented with the XLINK examples.In all cases this resulted in a blank web page, meaning - to my understanding! - that the XML syntax is incorrect.For xlink I consulted, among others, the W3C information like:http://www.w3schools.com/xlink/xlink_syntax.aspsummarised:Is there anybody who can give a code example parsing the contents of a linked XML file (see example above) including a mailto/xlink links?Secondary question, how do you pass (other) special characters such as &+euml; (ë)?This does not seem to work either from a XML file, that is, I cannot pass this kind of data within my example!Regards, Wim Ahlers.

Link to comment
Share on other sites

What you describe are practically all problems Data Islands carry. They are as attractive as the <font> tag once was... a variety of problems they present and for which no one is using them are:

  • Viewable only in IE5.5+. Infact, I can't believe this sentence: "N.b. the web page does display the data of the XML file correctly in the various web browsers.".
  • Only fills element's contents. It can't fill attribute's contents and unfortunatly, that's just the case with images, links and most of the other usefull stuff. XLink's purpose isn't about turning this text into links. The story is much more deeper.
  • Requres the XML to follow a consistant naming scheme. It can't handle "odd" XMLs.
  • It can't query attributes (as far as I'm aware).
  • A lack of XPath expressions, leaving you almost nothing.

And the list could go on, but there's no need for that.The best way to turn XML data into XHTML data has always been with XSLT. XSLT transformations can be executed either by launching the XML file (not what you want to do I guess) or by using this or similar JavaScript to call it inside an HTML page. Other ways include to call it with a server side scripting, but I guess you're trying to avoid that.

Link to comment
Share on other sites

boen_robot,Thanks for your reaction.So, if I understand correctly, text is possible, but for atributes like links and images it isn't.By the way, when I said "the web page does display the data of the XML file correctly in the various web browsers", I merely meant the latest releases of the most commonly used web browers used by my target audiance (a specific organization!).I did not mean all relaeses of all web browsers used by everybody.My apologies for the for the misunderstanding created by me.If I understand correctly, the only solution to create and control, as you call it, these "data islands" is to use a scripting language on either the client or the server side (your suggestion is javaScript on the client side...or [i guess!?!] php on the server side).In that case I opt for a server side solution in an attempt to be as transparant as possible for the client side (no dependencies - just using the browser as a 'dumb' terminal for displaying static web pages).However, if there is somebody who has an other solution for these kind of "data islands" than I am sure interested in the solution...Regards, Wim Ahlers.

Link to comment
Share on other sites

It's not me who calls it data islands. It's Microsoft. Look (again?) at this part of the XML tutorial at W3Schools. And it's not the XML that's called Data Islands. It's the method for getting the XML data into HTML :) .You can use pure JavaScript and/or PHP to get the XML data into the HTML, but that's not what I'm suggesting. I suggest you create an XSLT that will turn for example

<mailURL>john.doe@acme.inc.com</mailURL>

into

<a href="mailto:john.doe@acme.inc.com">john.doe@acme.inc.com</a>

etc.And then execute that XSLT transformation with the JavaScript code suggested above. The only thing JavaScript will do is to call the XSLT file and tell the browser to execute the instructions in it. The presentaion itself it controlled from the XSLT file itself.

Link to comment
Share on other sites

Boen_robot,Thanks again for your information. I was not familiar with the term "data islands"in this context.I have a different background (mainframe; core application programmer).Anyway, my knowledge of (X)HTML/XML is rudimentary and my knowledge of microsoft-anything is, basically, non-existent!I will ponder over, explore and exploit your information. Thanks for your time.Regards, Wim Ahlers.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...