While its not so busy at work during the festive period, i've decided to build a application to parse our HP plotters xml accounting file. The file is sent to my mail on a daily basis, with all the statistics of the previous day's print in. I've looked at basic XML Parsers all over the net, and all works, but the format of this HP file is a tad diffrent than your "normal" xml file, so I'm having difficulties parsing it.
Please assist.
My code and my method so far:
xml file:
c# method:
private void ParseXML(string filename)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(filename);
XmlNodeList jobname = xDoc.GetElementsByTagName("JOB_NAME");
XmlNodeList uniqueid = xDoc.GetElementsByTagName("UUID");
XmlNodeList accountid = xDoc.GetElementsByTagName("ACCOUNT_ID");
XmlNodeList userdefined = xDoc.GetElementsByTagName("USER_DEFINED");
XmlNodeList timestamp = xDoc.GetElementsByTagName("TIMESTAMP");
XmlNodeList printingtimestamp = xDoc.GetElementsByTagName("PRINTING_TIMESTAMP");
XmlNodeList jobstatus = xDoc.GetElementsByTagName("JOB_STATUS");
XmlNodeList username = xDoc.GetElementsByTagName("USER_NAME");
//XmlNodeList accountingsource = xDoc.GetElementsByTagName("SOURCE");
XmlNodeList inkcoveragecategory = xDoc.GetElementsByTagName("INK_COVERAGE_CATEGORY");
XmlNodeList printquality = xDoc.GetElementsByTagName("PRINT_QUALITY");
XmlNodeList printtype = xDoc.GetElementsByTagName("PRINT_TYPE");
XmlNodeList pages = xDoc.GetElementsByTagName("PAGES");
XmlNodeList copies = xDoc.GetElementsByTagName("COPIES");
XmlNodeList printingtime = xDoc.GetElementsByTagName("PRINTING_TIME");
XmlNodeList name = xDoc.GetElementsByTagName("NAME");
XmlNodeList quantity = xDoc.GetElementsByTagName("QUANTITY");
XmlNodeList size = xDoc.GetElementsByTagName("SIZE");
XmlNodeList width = xDoc.GetElementsByTagName("WIDTH");
XmlNodeList length = xDoc.GetElementsByTagName("LENGTH");
//XmlNodeList mediasource = xDoc.GetElementsByTagName("SOURCE");
XmlNodeList inkused = xDoc.GetElementsByTagName("INK_USED");
XmlNodeList consumeY = xDoc.GetElementsByTagName("CONSUME");
XmlNodeList consumeM = xDoc.GetElementsByTagName("CONSUME");
XmlNodeList consumeB = xDoc.GetElementsByTagName("CONSUME");
XmlNodeList consumeC = xDoc.GetElementsByTagName("CONSUME");
count = jobname.Count;
al = new ArrayList(count);
for (i = 0; i <= count-1; i++)
{
al.Add(
"Job Name: " + jobname[i].Attributes[0].InnerText + "\r\n" +
"Unique ID: " + uniqueid[i].Attributes[0].InnerText + "\r\n" +
"Account ID: " + accountid[i].Attributes[0].InnerText + "\r\n" +
"User Defined: " + userdefined[i].Attributes[0].InnerText + "\r\n" +
"Time Stamp: " + timestamp[i].Attributes[0].InnerText + "\r\n" +
"Printing Time Stamp: " + printingtimestamp[i].Attributes[0].InnerText + "\r\n" +
"Job Status: " + jobstatus[i].Attributes[0].InnerText + "\r\n" +
"Username: " + username[i].Attributes[0].InnerText + "\r\n" +
//"Accounting Source: " + accountingsource[i].Attributes[0].InnerText + "\r\n" +
"Ink Coverage Category: " + inkcoveragecategory[i].Attributes[0].InnerText + "\r\n" +
"Print Quality: " + printquality[i].Attributes[0].InnerText + "\r\n" +
"Print Type: " + printtype[i].Attributes[0].InnerText + "\r\n" +
"Pages: " + pages[i].Attributes[0].InnerText + "\r\n" +
"Copies: " + copies[i].Attributes[0].InnerText + "\r\n" +
"Printing Time Units: " + printingtime[i].Attributes[0].InnerText + "\r\n" +
"Printing Time: " + printingtime[i].Attributes[1].InnerText + "\r\n" +
"Media Vendor Name: " + name[i].Attributes[0].InnerText + "\r\n" +
"Media Name: " + name[i].Attributes[1].InnerText + "\r\n" +
"Media Quantity Units: " + quantity[i].Attributes[0].InnerText + "\r\n" +
"Media Quantity: " + quantity[i].Attributes[1].InnerText + "\r\n" +
"Size Units: " + size[i].Attributes[0].InnerText + "\r\n" +
"Width: " + width[i].Attributes[0].InnerText + "\r\n" +
"Length: " + length[i].Attributes[0].InnerText + "\r\n" +
//"Media Source: " + mediasource[i].Attributes[0].InnerText + "\r\n" +
"Ink Units: " + inkused[i].Attributes[0].InnerText + "\r\n" +
"Color Yellow: " + consumeY[i].Attributes[1].InnerText + "\r\n" +
"Color Magenta: " + consumeM[i].Attributes[1].InnerText + "\r\n" +
"Color Black: " + consumeB[i].Attributes[1].InnerText + "\r\n" +
"Color Cyan: " + consumeC[i].Attributes[1].InnerText
);
}
}
Riaan de LangePosted Dec 26, 2008, 9:06 AM
Job Name: D4VC#30LEV
Unique ID: 70bbd6b8-e5a3-4cad-86ce-a9b5f39cc176
Account ID:
User Defined:
Time Stamp: 20081218091804
Printing Time Stamp: 20081218172736
Job Status: 0
Username: SnydJ
Ink Coverage Category: B
Print Quality: 1
Print Type: 1
Pages: 1
Copies: 2
Printing Time Units: secondsx10
Printing Time: 2475
Media Vendor Name: HP
Media Name: Plain
Media Quantity Units: sqi
Media Quantity: 5104
Size Units: inchesx3600
Width: 127585
Length: 255125
Ink Units: microliters
Color Yellow: 301
Color Magenta: 301
Color Black: 301
Color Cyan: 301
obviously the bottom microliters is not being parsed correctly - don't know how to read the YMBC from xml individually...