for the love of dirt, help me parse xml....please

XCon

Banned
Jul 31, 2002
70
0
0
OK,
sorry about the title, I have been frustrated on this. I know nothing about xml, but would really like to learn. Anyway, I am trying to parse this file to an html page to view...
<?xml version="1.0" encoding="UTF-8" ?>
- <CoolMon>
- <Raw>
<Uptime>0 days, 02 hrs, 28 mins, 14 secs</Uptime>
<System_Thread_Count>313</System_Thread_Count>
<System_Processes_Count>32</System_Processes_Count>
<PageTotal>617</PageTotal>
<PageUsed>117</PageUsed>
<PageFree>500</PageFree>
<RAMTotal>254</RAMTotal>
<RAMUsed>132</RAMUsed>
<RAMFree>122</RAMFree>
<Processor_Usage>00.00</Processor_Usage>
<Network_Read_Stats>01.35</Network_Read_Stats>
<Network_Write_Stats>00.00</Network_Write_Stats>
<Network_Bytes_Read>39,891.19</Network_Bytes_Read>
<Network_Bytes_Written>41,703.14</Network_Bytes_Written>
<IP_Addresses>10.37.123.01</IP_Addresses>
<Computer_Name>PNS</Computer_Name>
<User_Name>User</User_Name>
<Date_and_Time>Date 12/08/02 Time 16:14</Date_and_Time>
<Blank />
<Drive_Space>31,593</Drive_Space>
<Processor_Type>i686</Processor_Type>
<File_Line_Data />
</Raw>
- <Formatted>
<Item_0>Proc %25: 00.00</Item_0>
<Item_1>Processes: 32 Threads: 313</Item_1>
<Item_2>0 days, 02 hrs, 28 mins, 14 secs</Item_2>
<Item_3>PageUsed: 117/PageTotal: 617</Item_3>
<Item_4>RAMUsed: 132/RAMTotal: 254</Item_4>
<Item_5>Date 12/08/02 Time 16:14</Item_5>
<Item_6>10.37.123.12</Item_6>
<Item_7>PNS</Item_7>
<Item_8>Threads: 313</Item_8>
<Item_9>RAMTotal: 254</Item_9>
<Item_10>RAMUsed: 132</Item_10>
<Item_11>RAMFree: 122</Item_11>
<Item_12>KB Read: 01.35</Item_12>
<Item_13>KB Write: 00.00</Item_13>
<Item_14>Date 12/08/02 Time 16:14</Item_14>
<Item_15>Drive C: 31,593</Item_15>
<Item_16>Processor: i686</Item_16>
</Formatted>
</CoolMon>
 

Moonbender

Golden Member
Oct 19, 2000
1,046
0
0
You probably know this, but IE displays XML files in a nice tree-like view ... that might be the easiest thing to do.
The proper technical route would be to use XSL (extensible stylesheet language) which does exactly what you want to do, produce formatted XHTML from an XML file. (Incidently, what IE displays when opening an XML file is just Microsofts default XSL at work.) Learning XSL isn't difficult, especially when you've got some background in programming, XML or at least HTML, but it will take some time nevertheless. If you only want to view this one XML file, then I doubt learning XSL is worth your time.
Finally, you can download one of the many XML editors (Google is your friend), which will help you view the file, and which (I assume) often contain some sort of export option to save the XML as HTML - I doubt it will look much better than in IE, though. There are also a couple of tools that will do what XSL does without actually requiring you to know XSL, you might want to try a Google on that, too.
 

XCon

Banned
Jul 31, 2002
70
0
0
[Q<html>
<head>
<title>PNS Webserver Stats</title>
<script language="JavaScript">
function UpdateReadings(){
dom = new ActiveXObject("Msxml.DOMDocument");
dom.async = false;
dom.load("http://10.37.123.12:61300");
cpu_load.innerHTML = dom.getElementsByTagName("Uptime")[0].firstChild.nodeValue;
cpu_thread.innerHTML = dom.getElementsByTagName("System_Thread_Count")[0].firstChild.nodeValue;
cpu_proc.innerHTML = dom.getElementsByTagName("System_Processes_Count")[0].firstChild.nodeValue;
cpu_pagetotal.innerHTML = dom.getElementsByTagName("Item_3")[0].firstChild.nodeValue;
cpu_date.innerHTML = dom.getElementsByTagName("Item_5")[0].firstChild.nodeValue;
cpu_usage.innerHTML = dom.getElementsByTagName("Processor_Usage")[0].firstChild.nodeValue;
drive_space.innerHTML = dom.getElementsByTagName("Drive_Space")[0].firstChild.nodeValue;
}
function CoolMon(){
window.setInterval('UpdateReadings()',5000);
}

</script>
</head>
<body onLoad="CoolMon()"> <!-- Make it run when loading the page -->
<!-- Insert data from the script into page flow -->
<font color="#0033FF" size="2" face="verdana">Uptime</font>: <SPAN ID="cpu_load" STYLE="position:relative; font-weight: bold;"></span> <br/>
<font color="#6600FF" size="2" face="verdana">Threads</font>: <SPAN ID="cpu_thread" STYLE="position:relative; font-weight: bold;"></span><br/>
<font color="#3399FF" size="2" face="verdana">Processes</font>: <SPAN ID="cpu_proc" STYLE="position:relative; font-weight: bold;"></span><br/>
<font color="#FF6633" size="2" face="verdana">Page Total</font>: <SPAN ID="cpu_pagetotal" STYLE="position:relative; font-weight: bold;"></span><br/>
<font color="#009933" size="2" face="verdana">Date & Time</font>:<SPAN ID="cpu_date" STYLE="position:relative; font-weight: bold;"></span><br/>
<font color="#CC0000" size="2" face="verdana">CPU%</font>: <SPAN ID="cpu_usage" STYLE="position:relative; font-weight: bold;"></span><br/>
<font color="#660000" size="2" face="verdana">Drive Space</font>: <SPAN ID="drive_space" STYLE="position:relative; font-weight: bold;"></span><br/>
<!-- SPAN ID must be the same as .InnerHTML property created in UpdateReadings() -->
</body>
</html> [/quote]

I got it,
this does it rather nicely (plain). That's what I wanted.