The online racing simulator
Troubles displaying data on a browser from an .xml file
Hi.
I've been trying to get a web page to display some data from an .xml file created by LFSPoints. I'm pretty new to xml to be honest, and i wouldn't call myself a HTML master either.
I've been looking at working examples and trying to work it out from there, but what i've come up with doesn't work and i'm now stuck.
Can anyone see why the below code does not fetch what i want it to?
I'm going to assume i'm either very close or way way off the mark with it.
The below .html file is hosted in the same directory as 'test.xml' which is a LFSPoints exported file.


<html>
<body>

<xml src="test.xml" id="rssc" async="false"></xml>

<br />Track:
<span datasrc="#rssc" datafld="TrackName"></span>
<br />Laps:
<span datasrc="#rssc" datafld="Laps"></span>


</body>
</html>

Obviously, this code is only a test to see if i can get it to work, i don't want to only display the Track and Lapcount.


So, any ideas?
If you need more info, just let me know.

Thanks for any help guys
Aren't you supposed to use an XSLT doc to convert from XML to XHTML etc., instead of doing it from the HTML doc?
I'm not sure how portable that is between browsers; I know that IE has what is referred to as a XML Data island, but as NAI points out its probably better to use an XSL stylesheets to transform the data you want.

A couple of quick ways of doing XSL is to allow the browser to do it, i.e.

You can use the XSLT document function e.g. document('file.xml')
to load XML resources. Note that in the browser with normal security settings the same origin policy applies meaning you can load XML data only from the server the original document comes from.

Or visa versa and insert a stylesheet into the XML document as such as...

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="print.xsl"?>

where "print.xsl" is name of your XSL stylesheet.

http://www.w3schools.com/xsl/ is a decent starting point on using XSL stylesheets.

Quote from GFresh :Hi.
I've been trying to get a web page to display some data from an .xml file created by LFSPoints. I'm pretty new to xml to be honest, and i wouldn't call myself a HTML master either.
I've been looking at working examples and trying to work it out from there, but what i've come up with doesn't work and i'm now stuck.
Can anyone see why the below code does not fetch what i want it to?
I'm going to assume i'm either very close or way way off the mark with it.
The below .html file is hosted in the same directory as 'test.xml' which is a LFSPoints exported file.


<html>
<body>

<xml src="test.xml" id="rssc" async="false"></xml>

<br />Track:
<span datasrc="#rssc" datafld="TrackName"></span>
<br />Laps:
<span datasrc="#rssc" datafld="Laps"></span>


</body>
</html>

Obviously, this code is only a test to see if i can get it to work, i don't want to only display the Track and Lapcount.


So, any ideas?
If you need more info, just let me know.

Thanks for any help guys

Quote from NotAnIllusion :Aren't you supposed to use an XSLT doc to convert from XML to XHTML etc., instead of doing it from the HTML doc?

Well, that code it basically an exact copy of a working example from the net, just with file names changed, and the data to be retrieved changed.
So, i dont know, this is why i need help
Never seen it be done like that tbh, I'd research into what Hollywood said. That's how I've learned to do it in uni anyways.
Quote from Hollywood :I'm not sure how portable that is between browsers; I know that IE has what is referred to as a XML Data island, but as NAI points out its probably better to use an XSL stylesheets to transform the data you want.

A couple of quick ways of doing XSL is to allow the browser to do it, i.e.

You can use the XSLT document function e.g. document('file.xml')
to load XML resources. Note that in the browser with normal security settings the same origin policy applies meaning you can load XML data only from the server the original document comes from.

Or visa versa and insert a stylesheet into the XML document as such as...

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="print.xsl"?>

where "print.xsl" is name of your XSL stylesheet.

http://www.w3schools.com/xsl/ is a decent starting point on using XSL stylesheets.

Ok thanks, i'll take a look at that
#7 - Tooby
Something like this
http://www.w3schools.com/xml/xml_parser.asp

For IE-6 I think...And you have to learn XSL then you're lost
<html>
<body>

<script type="text/javascript">

// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("cdcatalog.xml")

// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("cdcatalog.xsl")

// Transform
document.write(xml.transformNode(xsl))

</script>

</body>
</html>
I'm not an expert on XML by any means, but I'm going to look at adding something like XSL stylesheets to the export automatically in LFSPoints V2.3. It should have three options, one for plain XML, another for XML with a default XSL file, and one with a custom XSL file. Hopefully by adding these I can ditch the HTML export, which is a total pain to work with in C# (and is crap anyway). I've no idea when V2.3 will be out, as it's a pretty complicated release.

Edit: Incidentally if anyone has any XML export requests now is the time to tell me!
#9 - Tooby
Quote from DarkTimes :...Hopefully by adding these I can ditch the HTML export, which is a total pain to work with in C# (and is crap anyway). ...

First, sorry for editing in your text but my question is about (and is crap anyway). Do you think C# is crap? just wondering because I find C# nice to work with regarding XML. Search for how to Serialize / deserialze XML with C#.

I had a really good project before but can't find it at the moment...
Look here: http://www.codeproject.com/inf ... ;ed=10/19/2007&Page=1


Best Regards tooby
I meant the HTML export I wrote for LFSPoints is crap, not the C# language itself. Sorry for the confusion.

While C# has lots of nice classes to help you write XML files, the same cannot be said for HTML. I did end up writing my own HtmlWriter class, which works the same way as XmlWriter does, but even small web pages can have hundreds of lines of code, and programmatically writing them all is a bit of a nightmare.

In terms of C# the language, I love it! I wouldn't have worked on the same .NET program for almost six months if I didn't!
Quote from DarkTimes :I meant the HTML export I wrote for LFSPoints is crap, not the C# language itself. Sorry for the confusion.

While C# has lots of nice classes to help you write XML files, the same cannot be said for HTML. I did end up writing my own HtmlWriter class, which works the same way as XmlWriter does, but even small web pages can have hundreds of lines of code, and programmatically writing them all is a bit of a nightmare.

In terms of C# the language, I love it! I wouldn't have worked on the same .NET program for almost six months if I didn't!

Good that I missunderstood.
Found the project but you perhaps don't need it.
http://www.codeproject.com/csharp/xml_serializationasp.asp
Quote from DarkTimes :
While C# has lots of nice classes to help you write XML files, the same cannot be said for HTML. I did end up writing my own HtmlWriter class, which works the same way as XmlWriter does, but even small web pages can have hundreds of lines of code, and programmatically writing them all is a bit of a nightmare.

OK - I take this back. I just discovered that C# will transform XML/XSL files into XHTML, with the System.Xml.Xsl namespace. I think the word I'm looking for is...

Hooray!
Quote from GFresh :Hi.
I've been trying to get a web page to display some data from an .xml file created by LFSPoints. I'm pretty new to xml to be honest, and i wouldn't call myself a HTML master either.
I've been looking at working examples and trying to work it out from there, but what i've come up with doesn't work and i'm now stuck.
Can anyone see why the below code does not fetch what i want it to?
I'm going to assume i'm either very close or way way off the mark with it.
The below .html file is hosted in the same directory as 'test.xml' which is a LFSPoints exported file.

</Snip>

You might want to take a look at LFSPoints V2.3, as it will now automatically create web pages from the XML data. There is a new file in the base directory called 'LFSPoints.xsl', which contains all the style information for the page.

Just edit this file to how you want the page to appear, then when you export a championship as HTML it will do an XSL Transform on the XSL file and the normal XML output, and export a HTML web page.

It seems to work pretty well.
Quote from DarkTimes :You might want to take a look at LFSPoints V2.3, as it will now automatically create web pages from the XML data. There is a new file in the base directory called 'LFSPoints.xsl', which contains all the style information for the page.

Just edit this file to how you want the page to appear, then when you export a championship as HTML it will do an XSL Transform on the XSL file and the normal XML output, and export a HTML web page.

It seems to work pretty well.

You sir, are an absolute legend!
Thankyou VERY much!

EDIT: Just checked it out, it's great!. And with the .xsl, is as customisable as one could ask for!

FGED GREDG RDFGDR GSFDG