Combine Nodes of XML Files

I am trying to parse the XML file below to output the “name - version - date” from each nodes.

Sample desired output:
Samsung PM9A1 PCIe Gen4 NVMe Solid State Drive Firmware Update - 3630.9229 - December 09, 2022
Dell Precision 3260 and 3460 System BIOS - 2.10.0 - December 20, 2023
.
.
.

I can pull the list of names using this, but I am unsure how to combine the values.
node values of xpaths ("xmlns:a='http://www.w3.org/2001/XMLSchema-instance'","/updates/update/name/text()") of xml document of file "c:\dcu-check\DCUApplicableUpdates.xml"

> <?xml version="1.0"?>
> <updates xmlns:http://www.w3.org/2001/XMLSchema-instance xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="5.1.0" schemaVersion="1.2">
>   <update>
>     <release>43JVK</release>
>     <name>Samsung PM9A1 PCIe Gen4 NVMe Solid State Drive Firmware Update</name>
>     <version>3630.9229</version>
>     <date>December 09, 2022</date>
>     <urgency>Recommended</urgency>
>     <type>Firmware</type>
>     <category>Storage</category>
>     <file>FOLDER09109597M/1/Samsung-PM9A1-PCIe-Gen4-NVMe-Solid-State-Drive-Firmware_43JVK_WIN64_3630.9229_A00.EXE</file>
>     <bytes>13505304</bytes>
>   </update>
>   <update>
>     <release>V9M4T</release>
>     <name>Dell Precision 3260 and 3460 System BIOS</name>
>     <version>2.10.0</version>
>     <date>December 20, 2023</date>
>     <urgency>Urgent</urgency>
>     <type>BIOS</type>
>     <category>BIOS</category>
>     <file>FOLDER10822090M/1/Precision_3260_3460_2.10.0.exe</file>
>     <bytes>54650424</bytes>
>   </update>
>   <update>
>     <release>TN0XH</release>
>     <name>NVIDIA Quadro Pxxxx/RTX xxxx/RTX Axxxx/Txxxx Series Desktop Graphics Driver and NVIDIA Control Panel Application</name>
>     <version>31.0.15.3667</version>
>     <date>September 14, 2023</date>
>     <urgency>Urgent</urgency>
>     <type>Driver</type>
>     <category>Video</category>
>     <file>FOLDER10378186M/1/NVIDIA-Quadro-Pxxxx-RTX-xxxx-RTX-Axxxx-Txxx-Series_TN0XH_WIN64_31.0.15.3667_A00.EXE</file>
>     <bytes>929770768</bytes>
>   </update>
>   <update>
>     <release>NXT7Y</release>
>     <name>Intel Innovation Platform Framework Driver</name>
>     <version>1.0.11100.29710</version>
>     <date>October 24, 2022</date>
>     <urgency>Recommended</urgency>
>     <type>Driver</type>
>     <category>Chipset</category>
>     <file>FOLDER09123234M/4/Intel-Innovation-Platform-Framework-Driver_NXT7Y_WIN64_1.0.11100.29710_A10_02.EXE</file>
>     <bytes>15284232</bytes>
>   </update>
>   <update>
>     <release>JY2K3</release>
>     <name>Realtek High Definition Audio Driver</name>
>     <version>6.0.9582.1</version>
>     <date>November 20, 2023</date>
>     <urgency>Recommended</urgency>
>     <type>Driver</type>
>     <category>Audio</category>
>     <file>FOLDER10795723M/1/Realtek-High-Definition-Audio-Driver_JY2K3_WIN_6.0.9582.1_A81.EXE</file>
>     <bytes>329441208</bytes>
>   </update>
>   <update>
>     <release>KVVGF</release>
>     <name>Intel HID Event Filter Driver</name>
>     <version>2.2.2.1</version>
>     <date>October 24, 2022</date>
>     <urgency>Recommended</urgency>
>     <type>Driver</type>
>     <category>Input</category>
>     <file>FOLDER09072162M/2/Intel-HID-Event-Filter-Driver_KVVGF_WIN64_2.2.2.1_A18_01.EXE</file>
>     <bytes>11967248</bytes>
>   </update>
> </updates>

Discussion of XML Namespaces at Parsing Scheduled Task XML may be helpful.

Your top-level XML declaration doesn’t look correct - can you verify that it’s actually xmlns="http://www.w3.org/2001/XMLSchema-instance and not xmlns:http://www.w3.org/2001/XMLSchema-instance" ? The original version won’t load in my XML parser but after this update it does.

Once the xmlns: statement is corrected, I found we need to reference the namespace in the query as well. We need to change the xpath search to terminate at the ‘update’ node, and then retrieve the text values from the child nodes “name”, “version” and “date” of the “update” node:

q: (node value of child node of child nodes whose (node name of it = "name") of it & " - " & node value of child node of child nodes whose (node name of it = "version") of it & " - " & node value of child node of child nodes whose (node name of it = "date") of it) of xpaths ("xmlns:a='http://www.w3.org/2001/XMLSchema-instance'","/a:updates/a:update") of xml document of file "c:\temp\test.xml"
A: Samsung PM9A1 PCIe Gen4 NVMe Solid State Drive Firmware Update - 3630.9229 - December 09, 2022
A: Dell Precision 3260 and 3460 System BIOS - 2.10.0 - December 20, 2023
A: NVIDIA Quadro Pxxxx/RTX xxxx/RTX Axxxx/Txxxx Series Desktop Graphics Driver and NVIDIA Control Panel Application - 31.0.15.3667 - September 14, 2023
1 Like

Thanks for your reply Jason.

I recreated the XML and see the XML declaration is this:
<updates xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="5.1.0" schemaVersion="1.2">

I do see what you mean though. When I remove the :xsi text from xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" so it’s just xmlns="http://www.w3.org/2001/XMLSchema-instance, the query you shared works.

Odd.

This works though with the original XML. Thanks for the assist.

q:(node value of child node of child nodes whose (node name of it = "name") of it & " - " & node value of child node of child nodes whose (node name of it = "version") of it & " - " & node value of child node of child nodes whose (node name of it = "date") of it) of xpaths ("xmlns:a='http://www.w3.org/2001/XMLSchema-instance'","/updates/update") of xml document of file "c:\dcu-check\DCUApplicableUpdates.xml"
A: Samsung PM9A1 PCIe Gen4 NVMe Solid State Drive Firmware Update - 3630.9229 - December 09, 2022
A: Dell Precision 3260 and 3460 System BIOS - 2.10.0 - December 20, 2023
A: NVIDIA Quadro Pxxxx/RTX xxxx/RTX Axxxx/Txxxx Series Desktop Graphics Driver and NVIDIA Control Panel Application - 31.0.15.3667 - September 14, 2023
A: Intel Innovation Platform Framework Driver - 1.0.11100.29710 - October 24, 2022
A: Realtek High Definition Audio Driver - 6.0.9582.1 - November 20, 2023
A: Intel HID Event Filter Driver - 2.2.2.1 - October 24, 2022
T: 0.804 ms

Ah, I see. I was mistakenly taking that first namespace to be the ‘default’ namespace, when really it’s just another declared (and unused!) namespace in the XML.

The discussion at https://stackoverflow.com/questions/41035128/what-is-the-difference-between-xsd-and-xsi may be helpful in understanding the differences between xmlns="some default", xmlns:xsi="some value", and xmlns:xsd="some value"

Since all the elements then are in the default namespace, we don’t actually have to specify the namespace at all in the xpath query, and then we can simplify the query statement a bit more; this maybe helpful if we had to add more elements or grandchild elements instead of direct child nodes. We can simplify the query a bit further to

q: (concatenation " - " of node values of xpaths ("name/text()"; "version/text()"; "date/text()") of it ) of xpaths ("/updates/update") of xml document of file "c:\temp\test.xml"

A: Samsung PM9A1 PCIe Gen4 NVMe Solid State Drive Firmware Update - 3630.9229 - December 09, 2022
A: Dell Precision 3260 and 3460 System BIOS - 2.10.0 - December 20, 2023
A: NVIDIA Quadro Pxxxx/RTX xxxx/RTX Axxxx/Txxxx Series Desktop Graphics Driver and NVIDIA Control Panel Application - 31.0.15.3667 - September 14, 2023

1 Like