Newbie: Best layout for XML file?

H

HerHusband

I have a database that I would like to add XML exporting to, and then be
able to display that information "EASILY" on a web page.

The data consists of three simple text fields "title", "supplies", and
"notes". The supplies and notes fields may have any number of text lines,
including blank lines. For example, a sample record may look like this:

Title: Doghouse

Supplies: 1 sheet of plywood
4 2x4x8's
1 bundle roofing shingles

Notes: Go to store, and buy supplies.

Store them in a dry place.
Cut, nail, insert dog.


My first attempt at XML was something like this:

<?xml version="1.0" ?>
<project>
<title>Doghouse</title>
<supplies>
1 sheet of plywood
4 2x4x8's
1 bundle roofing shingles
</supplies>
<notes>
Go to store, and buy supplies.

Store them in a dry place.
Cut, nail, insert dog.
</notes>
</project>

This seems to work OK, and I can show it on a web page as easily as this:

<html>
<body>
<xml src="test.xml" id="project" async="false"></xml>
Title: <span datasrc="#project" datafld="title"></span><br>
Supplies: <span datasrc="#project" datafld="supplies"></span><br>
Notes: <span datasrc="#project" datafld="notes"></span><br>
</body>
</html>

However, I understand "data islands" like this are an IE specific way of
displaying XML data. I'm also concerned that the carriage returns in each
field may get lost or displayed incorrectly on some systems.

One way around that "might" be to switch to something like this:

<?xml version="1.0" ?>
<project>
<title>Doghouse</title>
<supplies>1 sheet of plywood</supplies>
<supplies>4 2x4x8's</supplies>
<supplies>1 bundle roofing shingles</supplies>
<notes>Go to store, and buy supplies.</notes>
<notes></notes>
<notes>Store them in a dry place.</notes>
<notes>Cut, nail, insert dog.</notes>
</notes>
</project>

However, when I change the XML file like this, the HTML web page above
fails to show the supplies and notes fields. So, I'm not quite sure how
best to handle this.

Can anyone tell me which would be the preferred layout, and the easiest way
to display it on an HTML web page?

Thanks,

Anthony
 
A

Andy Dingley

Can anyone tell me which would be the preferred layout, and the easiest way
to display it on an HTML web page?

Server-side XSLT.

Often discussed topic - search the ng for it.
 
P

Peter Flynn

HerHusband wrote:
[...]
My first attempt at XML was something like this:

<?xml version="1.0" ?>
<project>
<title>Doghouse</title>
<supplies>
1 sheet of plywood
4 2x4x8's
1 bundle roofing shingles
</supplies>
<notes>
Go to store, and buy supplies.

Store them in a dry place.
Cut, nail, insert dog.
</notes>
</project>

This seems to work OK

Better to put each item in its own element within supplies and notes.
<?xml version="1.0" ?>
<project>
<title>Doghouse</title>
<supplies>1 sheet of plywood</supplies>
<supplies>4 2x4x8's</supplies>
<supplies>1 bundle roofing shingles</supplies>
<notes>Go to store, and buy supplies.</notes>
<notes></notes>
<notes>Store them in a dry place.</notes>
<notes>Cut, nail, insert dog.</notes>
</notes>
</project>

That goes to the opposite extreme. Maybe half-way is best:

<project>
<title>Doghouse</title>
<supplies>
<item>1 sheet of plywood</item>
<item>4 2x4x8s</item>
<item>1 bundle roofing shingles</item>
</supplies>
....etc...

That way, XSLT can accurately handle both the individual items *and* the
supplies as a group. If you were doing this on a large scale, you might
want <item quantity="1" unit="sheet">plywood</item> so that you can be
able to access the data values (eg to make comparisons between projects
against a cost database).

Incidentally, someone posted recently asking about "XML Data Modelling",
and I think this is the kind of thing they had in mind.

///Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top