Skip to content

Parse HP's XML Printer Accounting File

Riaan de Lange

Asked Dec 26, 2008, 4:03 AM EST1 answer
Share
LinkedInX
Hi everyone

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:
<?xml version="1.0" encoding="UTF-8"?>
<AccountingInfo version="1.2">
<Current_Printer_Configuration>
<Product_Number>Q1276A</Product_Number>
<Serial_Number>DK725JW</Serial_Number>
<Product_Name>HP Designjet 4500mfp</Product_Name>
<FW_Version>GW_10.1.1.4</FW_Version>
</Current_Printer_Configuration>
<ACCOUNTING_INFO>
<JOB_NAME value="D4VC#30LEV"/>
<UUID value="70bbd6b8-e5a3-4cad-86ce-a9b5f39cc176"/>
<ACCOUNT_ID value=""/>
<USER_DEFINED value=""/>
<TIMESTAMP value="20081218091804"/>
<PRINTING_TIMESTAMP value="20081218172736"/>
<JOB_STATUS value="0"/>
<USER_NAME value="SnydJ"/>
<SOURCE value="1"/>
<INK_COVERAGE_CATEGORY value="B"/>
<PRINT_QUALITY value="1"/>
<PRINT_TYPE value="1"/>
<PAGES value="1"/>
<COPIES value="2"/>
<PRINTING_TIME units="secondsx10" value="2475"/>
<MEDIA_INFO>
<NAME vendor-name="HP" media-name="Plain"/>
<QUANTITY units="sqi" value="5104"/>
<SIZE units="inchesx3600">
<WIDTH value="127585"/>
<LENGTH value="255125"/>
</SIZE>
<SOURCE value="3"/>
</MEDIA_INFO>
<INK_INFO>
<INK_USED units="microliters" value="Unknown"/>
<CONSUME color="Y" quantity="301"/>
<CONSUME color="M" quantity="281"/>
<CONSUME color="B" quantity="1122"/>
<CONSUME color="C" quantity="208"/>
</INK_INFO>
</ACCOUNTING_INFO>


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
                        );
            }
        }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Output:

    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...
    0