Jump to content

What am I doing wrong??


Aus_Steph
 Share

Recommended Posts

Im just learning XML, and cannot work out why this wont work when I try to embed the XML into HTML.Here are my codes:<xml id="steph"><family> <mother> <gender>Female</gender> <age>60</age> <name>Pam</name> </mother> <father> <gender>Male</gender> <age>61</age> <name>Geoff</name> </father> <child> <gender>Female</gender> <age>28</age> <name>Stephanie</name> </child></family></xml>And my HTML:<html><body><xml id="steph" src="steph.xml"></xml><table border="1" datasrc="#steph"><tr><td><span datafld="gender"></span></td><td><span datafld="age"></span></td><td><span datafld="name"></span></td></tr></table></body></html>Can Anyone tell me what I am doing wrong? I have just saved both into a folder on my desktop. Thanks!

Link to comment
Share on other sites

Yes. It's normal to have such popo-up. And by the way, the XML prolog looks like this:

<?xml version="1.0" ?>

Delete the XML element (both the opening and closing tags) and replace it with that. Also, note that only IE is capable of running XML inside HTML with Data Islands."For the sake of completeness":

<?xml version="1.0" ?><family><mother><gender>Female</gender><age>60</age><name>Pam</name></mother><father><gender>Male</gender><age>61</age><name>Geoff</name></father><child><gender>Female</gender><age>28</age><name>Stephanie</name></child></family>

Link to comment
Share on other sites

I got it! The reason is inconsistent element names. A bad habbit you should try to avoid anyway. What do I mean? Well, each element in which you have the gender, age and name is different. Make it something universal and if you want to specify who is who, you can create a new element with this data. Here's a fixed kind of code:

<?xml version="1.0" ?><family><member><type>mother</type><gender>Female</gender><age>60</age><name>Pam</name></member><member><type>father</type><gender>Male</gender><age>61</age><name>Geoff</name></member><member><type>child</type><gender>Female</gender><age>28</age><name>Stephanie</name></member></family>

Link to comment
Share on other sites

Haha excellent. Thankyou!So each bit of info needs the same opening and closing tags as the next one in that table. Yeh?OK, so if XML data islands are only supported by IE, I should forget about using it in web design and stuff right? Sorry I am reallllllly clueless with some stuff!

Link to comment
Share on other sites

So each bit of info needs the same opening and closing tags as the next one in that table. Yeh?

Data Islands- yes. All other methods of extracting XML data (such as XSLT)- not necessary but reccomended. Just another reason for you to forget data islands and move on to the cooler stuff :) .
Link to comment
Share on other sites

I mean every other method of extracting, using and manipulating XML data. XSLT for starters, but also server side scripting languages, XML DOM, other XML based languages (SVG, XLink, etc.) and maybe something else I've missed.

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
 Share

×
×
  • Create New...