Reading an XML file

(imported topic written by homer91)

the file is in C:\Program Files\Hewlett-Packard\HP Active Support\Logs and is called battery.xml

file output:

<?xml version="1.0" ?>

7800

7352

7352

0

64

25

12526

0

10800

HP

16608

0

4178

4180

4180

0

1

100

98

True

40012 18169

19/06/2008

365

I have tried

If exsits file “C:\Program Files\Hewlett-Packard\HP Active Support\Logs\battery.xml” then (node values of child nodes of selects “/Hewlett-Packard” of xml document of file “C:\Program Files\Hewlett-Packard\HP Active Support\Logs\battery.xml”) as trimmed string else “NA”

but get undefined as a result

also tried

attribute 1 of select “/hewlett packard” of xml document of file (“C:\Program Files\Hewlett-Packard\HP Active Support\Logs\battery.xml”) as xml

but just get an error

any help appreciated

(imported comment written by MattBoyd)

You’re close, but you have a few syntax errors.

If you want all of the values under the tag, you could probably use something like this:

If exists file “C:\Program Files\Hewlett-Packard\HP Active Support\Logs\battery.xml” then ((node values of child nodes of child nodes of selects “/Hewlett-Packard/HPBatteryCheck/Battery” of xml document of file “C:\Program Files\Hewlett-Packard\HP Active Support\Logs\battery.xml”) as trimmed string) else “NA”

If you need an attribute of you can use something like this:

If exists file “C:\Program Files\Hewlett-Packard\HP Active Support\Logs\battery.xml” then ((node value of attribute 0 of selects “/Hewlett-Packard/HPBatteryCheck” of xml document of file “C:\Program Files\Hewlett-Packard\HP Active Support\Logs\battery.xml”)) else “NA”

(imported comment written by homer91)

thanks for the help.

the first one obviously returns multiple results so I created a bigfix report but when exported to excel is all over the place and unusable.

I would prefer to return the values as seperate properties, from what you gave me it returned CND914219D

to get the properties lower down I have tried modifying what you sent me

selects “/Hewlett-Packard/HPBatteryCheck/DesignCapacity”

selects “/Hewlett-Packard/HPBatteryCheck/battery/DesignCapacity” using the full relevance of course but still just get an error returned

is this another syntax mistake?

(imported comment written by MattBoyd)

Homer, I think you may be a bit confused about the differences between elements and attributes.

The first example that I gave you returns the value of each element in /Hewlett-Packard/HPBatteryCheck/Battery. That is, the values between the opening and closing tag of each element (for example: 4178)

The second example returns the first attribute from /Hewlett-Packard/HPBatteryCheck. Attributes are the values contained within an xml tag. In this case, it was the unitSerialNumber attribute within the HPBatteryCheck tag, since that’s the first attribute in that tag.

If you’re still confused about the difference, or could use a bit more information on how XML works, I strongly recommend going through the

W3Schools XML tutorial

.

Back to your question, if you want the element value of DesignCapacity, you can use a modified version of my first example:

If exists file “C:\Program Files\Hewlett-Packard\HP Active Support\Logs\battery.xml” then ((node values of child nodes of selects “/Hewlett-Packard/HPBatteryCheck/Battery/DesignCapacity” of xml document of file “C:\Program Files\Hewlett-Packard\HP Active Support\Logs\battery.xml”) as trimmed string) else “NA”

(imported comment written by homer91)

your right, I am confused or at least I was, a little knowledge goes a long way, sorted thanks for all your help :wink:

(imported comment written by homer91)

I am trying to write a custom report to pull all the data now and am using this

<?Relevance trs of (td of ( (if exists (name of it) then (name of it) else "N/A") & "," & (if (exists results (it, bes property "HP batt design capacity (temp)")) then (if (exists (values of results (it, bes property "HP batt design capacity (temp)"))) then concatenation "," of (values of results (it, bes property "HP batt design capacity (temp)")) else "N/A") else "N/A") ) ) of bes computers whose ( ( ( (exists result (it, bes property "Computer Manufacturer")) and (exists (value of result (it, bes property "Computer Manufacturer"))) and ((value of result (it, bes property "Computer Manufacturer"))="Hewlett-Packard" OR (value of result (it, bes property "Computer Manufacturer"))="HP") ) and ( (exists operating system of it) and (operating system of it as lowercase="winxp 5.1.2600") ) ) ) ?>
Computer Name,Hewlett-Packard Battery Info

I then copy and paste this section and change for other values to get the other data

(if exists (name of it) then (name of it) else “N/A”) &

“,” & (if (exists results (it, bes property “HP batt design capacity (temp)”)) then (if (exists (values of results (it, bes property “HP batt design capacity (temp)”))) then

concatenation “,” of (values of results (it, bes property “HP batt design capacity (temp)”)) else “N/A”) else “N/A”)

problem is I get parse errors - is this a problem with my syntax?

last but not least if I go with the first code I get mutiple entries, now this could be one of two reasons

my code - more than likely

utility that creates XMl was run more than once and appends the file

any suggestions?

just another thing I have found, it doesnt seem to return the same amount i.e

client1 5130, 5130, 5130, 5130, 5130

client 2 5130, 4000

client 3 5130, 5130, 5130, 5130, 5130, 5130, 5130, 5130, 5130, 5130

(imported comment written by MattBoyd)

Hey homer,

I’m not sure why it wouldn’t return the same amounts for clients. Assuming that the value it records is what’s in the XML file, it could be an issue with the HP software. I really don’t know much about it so I can’t say for sure.

I have not created reports in BigFix (yet) so I can’t comment much on your relevance there. Perhaps one of the folks from BigFix could assist you here. What syntax errors are you getting?

(imported comment written by homer91)

I’m getting unable to parse expression. dont worry about it, Im sure a few rounds of trial and error and I will get it.

(imported comment written by homer91)

OK, have moved away from selects as was getting nowhere fast and am now using Xpaths

node value of attribute 0 of xpaths "//Hewlett-Packard

last()

/HPBatteryCheck

last()

" of xml document of file “C:\Program Files\Hewlett-Packard\HPActive Support\Logs\battery.xml”

but this works for some clients and not others, any ideas why, on the ones it works on you get the serial number from this on others you get an error.

when I ran localy on my system through a relevance debugger I get the message

“Error: Singular expression refers to nonexistent object.”

any ideas why as I have manually checked the file is there and contains the data?

(imported comment written by MattBoyd)

Hey homer,

Could I see the xml file that is on your system? I think I ran into issues using XPath on XML files that had no root element… but I don’t believe I got that error. At any rate, I’ll be happy to give it a shot myself.

Thanks

Matt

(imported comment written by homer91)

the contents o the xml are at the top of the thread

(imported comment written by MattBoyd)

Hey homer,

I tried your relevance with the xml at the top of this post and it works fine. This leads me to believe that there may be something slightly different with the XML on the clients where this is failing. I believe you’ve mentioned that the application that generates this file continues to append updated results to the end of the file (which is why you’re using last()). Are you finding that the relevance is failing specifically on clients where the application has written several of these entries?

(imported comment written by homer91)

good point but no, just tested on mine, had multiple entries and relevance expression returns “Error: Singular expression refers to nonexistent object.”

removed extra entries and ran again but same error

(imported comment written by MattBoyd)

Do you mind if I had a look at that particular XML? I realize it should be the same as what’s at the top of this post, but there may be a very slight difference…

Matt

(imported comment written by homer91)

sure, here it is

(imported comment written by MattBoyd)

That file is missing the closing tag at the end, so the file is technically not XML valid. When I add this closing tag to the file, the relevance works fine. Any ideas why this may have been missing?

(imported comment written by homer91)

it could have been whenI manually edited to remove the multiple entries when testing the relevance to see was the mutiple entries the issue, this would not be the case with the other clients through out the enterprise but I will double-check

(imported comment written by homer91)

OK, I deleted the file and then ran the tool again that we are running throughout the enterprise to create these log files and here it is…

(imported comment written by MattBoyd)

Hmm… that one appears to be fine. The only thing I can suggest at this point is look at the contents of the XML file on a machine where the relevance failed. You may get more clues from that…

I’ll be happy to take a look at those as well if you’d like.

Matt

(imported comment written by homer91)

thanks for your help, will keep investigating and may just take you up on your offer