XML Data Request

Soldato
Joined
30 Dec 2004
Posts
2,869
Location
Stoke-on-Trent
I could do with a little help or point in the right direction.

I have a datalogger at work that generates a html/xml file to view realtime data. Now the resulting webpage shows quite a lot of items but I only want to display certain tags.

How can I read an xml file and then pull the bits of data I want from it and display in another page (just basic text will do me)

Sorry if it sounds confusing but half the problem is being able to ask the right question.

Example xml in spoiler that I'm trying to pull info from - I want to pull tag and corresponding value tags.
<Channels>
<DeviceTag>Mills Logger</DeviceTag>
<SerialNumber>11230692</SerialNumber>
<EnabledAnalogChannels>4</EnabledAnalogChannels>
<EnabledDigitalChannels>0</EnabledDigitalChannels>
<EnabledRemoteChannels>0</EnabledRemoteChannels>
<EnabledVirtualChannels>0</EnabledVirtualChannels>
<AnalogChannels>
<Channel>
<Tag>Mill 11</Tag>
<Value> -0.012971</Value>
<Unit/>
<Logged>Yes</Logged>
</Channel>
<Channel>
<Tag>Mill 12</Tag>
<Value> 0.057503</Value>
<Unit/>
<Logged>Yes</Logged>
</Channel>
<Channel>
<Tag>Mill 21</Tag>
<Value> 0.000720</Value>
<Unit/>
<Logged>Yes</Logged>
</Channel>
<Channel>
<Tag>Mill 22</Tag>
<Value> 0.000711</Value>
<Unit/>
<Logged>Yes</Logged>
</Channel>
</AnalogChannels>
<VirtualChannels/>
</Channels>
 
No idea, this is why I'm asking what questions I need to ask ;)

Can it be done through a web browser as javascript then? As my first intention is to generate another webpage puling just bits of data I need from numerous xml files
 
You can do it with an XSL style sheet, so all you need to do is open the XML file with your browser


something like this:

File: channels.xml
<?xml version="1.0" encoding="ISO-8859-1"?>

<?xml-stylesheet type="text/xsl" href="Style.xsl"?>

<Channels>
<DeviceTag>Mills Logger</DeviceTag>
<SerialNumber>11230692</SerialNumber>
<EnabledAnalogChannels>4</EnabledAnalogChannels>
<EnabledDigitalChannels>0</EnabledDigitalChannels>
<EnabledRemoteChannels>0</EnabledRemoteChannels>
<EnabledVirtualChannels>0</EnabledVirtualChannels>
<AnalogChannels>
<Channel>
<Tag>Mill 11</Tag>
<Value> -0.012971</Value>
<Unit/>
<Logged>Yes</Logged>
</Channel>
<Channel>
<Tag>Mill 12</Tag>
<Value> 0.057503</Value>
<Unit/>
<Logged>Yes</Logged>
</Channel>
<Channel>
<Tag>Mill 21</Tag>
<Value> 0.000720</Value>
<Unit/>
<Logged>Yes</Logged>
</Channel>
<Channel>
<Tag>Mill 22</Tag>
<Value> 0.000711</Value>
<Unit/>
<Logged>Yes</Logged>
</Channel>
</AnalogChannels>
<VirtualChannels/>
</Channels>

File: Style.xsl
<?xml version="1.0" encoding="ISO-8859-1" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>Tag</th>
<th>Value</th>
</tr>

<xsl:for-each select="Channels/AnalogChannels/Channel">
<tr>
<td>
<xsl:value-of select="Tag" />
</td>
<td>
<xsl:value-of select="Value" />
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Just make sure they are saved in the same directory, then open Channels.xml up in your web browser
 
Last edited:
Back
Top Bottom