Parsing USMT Estimate Output XML file

Bad etiquette to post here like this but was not sure how else to do it or where.

I am trying to get the value from the 4096 line in the following xml file which I want to give me the value 103978913792. This is used from a USMT Estimate xml output. I then want to convert it to MB, GB etc based on that value. I am assuming it is using *4096 if I grab the value from that line or *2048 based on that line etc.

<?xml version="1.0" encoding="UTF-8"?>
<PreMigration>
  <storeSize>
    <size clusterSize="0">103971021896</size>
    <size clusterSize="0">103971021896</size>
    <size clusterSize="512">103971937792</size>
    <size clusterSize="1024">103972934656</size>
    <size clusterSize="2048">103974961152</size>
    <size clusterSize="4096">103978913792</size>
    <size clusterSize="8192">103987011584</size>
    <size clusterSize="16384">104003108864</size>
    <size clusterSize="32768">104035909632</size>
    <size clusterSize="65536">104104394752</size>
    <size clusterSize="131072">104240513024</size>
    <size clusterSize="262144">104513667072</size>
    <size clusterSize="524288">105062596608</size>
    <size clusterSize="1048576">106180902912</size>
  </storeSize>
  <temporarySpace>
    <size>22778528</size>
  </temporarySpace>
</PreMigration>

Using this just gives me:
Q: node values of xpaths “/PreMigration/storeSize/size/@clusterSize” of xml document of file “USMTSpaceUsage.xml” of folders “__BESData__Global\Logs” of parent folder of client as integer

A: 0
A: 0
A: 512
A: 1024
A: 2048
A: 4096
A: 8192

I have also tried:
Q: ( node value of child node of selects “size” of it) of selects “PreMigration/storeSize/@clusterSize:4096” of xml document of file “USMTSpaceUsage.xml” of folders “__BESData__Global\Logs” of parent folder of client

And

Q: (node values of attributes “4096” of it) of child nodes of child nodes of child nodes whose (node name of it as lowercase = “4096”) of selects (“PreMigration/storeSize/size/@clusterSize”) of xml document of file “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData__Global\Logs\USMTSpaceUsage.xml” as integer

I am so unfamiliar with xml parsing.

I want to make this as an Analysis so we can report on all the machine after I deploy the USMT Estimate action and have them generate this xml file. Any chance you can help me with it? Or at least tell me where to properly post this request. Again, I apologize for putting this here. I have tried so many variations but cant get the syntax right. I have read all the other topic but it seems this file is unique in its formatting?

No need to apologize at all, and you’ve definitely found the right place to ask. XML parsing tends to be especially tricky in my opinion, and it seems like I have to re-learn it every time I look.

So I’ll start with your first query, since that looks really close to what we want, and post the process I went through to get to an answer, and at the end I think I have something that’ll work for you.

I copied your file content to c:\temp\test.xml for my testing and to illustrate the part of the query we care about.

Starting with what you had, we can see this is really close to what we want:

Q: node values of xpaths "/PreMigration/storeSize/size/@clusterSize" of xml document of file "c:\temp\test.xml" A: 0 A: 0 A: 512 A: 1024 A: 2048 A: 4096 A: 8192 A: 16384 A: 32768 A: 65536 A: 131072 A: 262144 A: 524288 A: 1048576 T: 0.452 ms I: plural string

But I don’t know what properties are available for an ‘xpath’, so I’ll go up one level and figure out what type it is, and then what properties are available for that type. The first query may give me an error, but at least it’ll show me what type I’m looking at:

q: xpaths "/PreMigration/storeSize/size/@clusterSize" of xml document of file "c:\temp\test.xml" E: This expression evaluates to an unrepresentable object of type "xml dom node" T: 0.443 ms I: plural xml dom node

q: properties of type "xml dom node" A: node name of <xml dom node>: string A: node type of <xml dom node>: integer A: node value of <xml dom node>: string A: owner document of <xml dom node>: xml dom document A: parent node of <xml dom node>: xml dom node A: first child of <xml dom node>: xml dom node A: last child of <xml dom node>: xml dom node A: previous sibling of <xml dom node>: xml dom node A: next sibling of <xml dom node>: xml dom node A: child node <integer> of <xml dom node>: xml dom node A: child nodes of <xml dom node>: xml dom node A: attribute <integer> of <xml dom node>: xml dom node A: attribute <string> of <xml dom node>: xml dom node A: attributes of <xml dom node>: xml dom node A: selects <string> of <xml dom node>: xml dom node A: xpaths <string> of <xml dom node>: xml dom node A: xpaths <( string, string )> of <xml dom node>: xml dom node T: 0.288 ms I: plural property

From this, I think both “node values”, “child nodes” and “attributes” look interesting. I’ll see if I can figure out what the node names and node values are from our original query:

q: (node names of it, node values of it) of xpaths "/PreMigration/storeSize/size/@clusterSize" of xml document of file "c:\temp\test.xml" A: clusterSize, 0 A: clusterSize, 0 A: clusterSize, 512 A: clusterSize, 1024 A: clusterSize, 2048 A: clusterSize, 4096 A: clusterSize, 8192 A: clusterSize, 16384 A: clusterSize, 32768 A: clusterSize, 65536 A: clusterSize, 131072 A: clusterSize, 262144 A: clusterSize, 524288 A: clusterSize, 1048576 T: 0.659 ms I: plural ( string, string )

As expected, we’re getting the same “values” as the previous query, but this shows us that the “node” we are looking at is “clusterSize”. XML is treating the “clusterSize” attribute as a node all it’s own. Really, I think we need the node above the “clusterSize” value, to get to the “size” node. The “size” node would have an attribute of clusterSize, and a value of the … whatever that big number represents. So I move the xpath up one level, and look at the child nodes of its results. (I probably could have left the xpath as it was, and instead start looking at “parent node of it”, but I’ll leave that as an exercise for the reader. There are probably ten other ways to do this with ‘selects’ as well.)

In this query, I want to check that I’m on the right path to find the “size” node, which should have the “clusterSize” attribute and the large node values:

(edit added “node name of it” to show we’re looking at the ‘size’ node, which has a single child node (the large integer value) )

q: ((node names of it, node values of it) of attributes of it, node name of it, node value of child nodes of it) of child nodes of xpaths "/PreMigration/storeSize" of xml document of file "c:\temp\test.xml" A: ( clusterSize, 0 ), size, 103971021896 A: ( clusterSize, 0 ), size, 103971021896 A: ( clusterSize, 512 ), size, 103971937792 A: ( clusterSize, 1024 ), size, 103972934656 A: ( clusterSize, 2048 ), size, 103974961152 A: ( clusterSize, 4096 ), size, 103978913792 A: ( clusterSize, 8192 ), size, 103987011584 A: ( clusterSize, 16384 ), size, 104003108864 A: ( clusterSize, 32768 ), size, 104035909632 A: ( clusterSize, 65536 ), size, 104104394752 A: ( clusterSize, 131072 ), size, 104240513024 A: ( clusterSize, 262144 ), size, 104513667072 A: ( clusterSize, 524288 ), size, 105062596608 A: ( clusterSize, 1048576 ), size, 106180902912 T: 1.187 ms I: plural ( ( string, string ), string, string )

Bingo! Now to find the one node that we want - the one with a clusterSize of 4096:

q: ((node names of it, node values of it) of attributes of it, node values of child nodes of it) of child nodes whose (node value of attribute "clusterSize" of it = "4096") of xpaths "/PreMigration/storeSize" of xml document of file "c:\temp\test.xml" A: ( clusterSize, 4096 ), 103978913792 T: 0.635 ms I: plural ( ( string, string ), string )

Now it’s just a matter of taking the value of the right child node, convert it to integer, and do the divisions however you want to represent it. If it’s in bytes as I expect, then I divide by 1024 to get KB, divide by 1024 again to get MB, and divide by 1024 again to get GB:

q: (it / 1024 / 1024 / 1024) of (node values of child nodes of it as integer) of child nodes whose (node value of attribute "clusterSize" of it = "4096") of xpaths "/PreMigration/storeSize" of xml document of file "c:\temp\test.xml" A: 96 T: 0.540 ms I: plural integer

Wow!! Thank you so much, Jason. I just learned more about XML parsing from your post than I have reading all others. The solution worked perfectly, of course. Thank you again.