Jump to content
Sign in to follow this  

_XMLDOMWrapper and namespace

Recommended Posts

Hi All,

I'm trying to process a XML file using the _XMLDOMWrapper UDF which worked very well for me so far.

Unfortunately I am struggling with a different XML format now.

I don't seem to be able to access any nodes after the root node unless I simplify the root node (what I'd like to avoid).

Here's the XML format:

<Systems Version="3.00" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:schemas-fujitsu-siemens-com:software-preload" xsi:noNamespaceSchemaLocation="HWInfo3.00.xsd">
    <IndividualSoftwareID />
    <CustomerSerialNumber />
    <IMEINumber />
        <MACAddress type="OnBoard">00:12:34:56:78:90</MACAddress>
    <SoftwareModules />
    <Product>Celsius M470-2</Product>

AU3 Test:

#include <Array.au3>
#include <_XMLDomWrapper.au3>
Local $inputFile = FileOpenDialog("Select XML", @ScriptDir, "XML (*.xml)", 1)
If FileExists($inputFile) Then
    _XMLFileOpen($inputFile, 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:schemas-fujitsu-siemens-com:software-preload" xsi:noNamespaceSchemaLocation="HWInfo3.00.xsd"')
    If Not @error Then
        $aTemp = _XMLGetChildNodes("/Systems")
        MsgBox(0,"Error","Error opening File: " & @error)

I'm pretty sure my error is in the _XMLFileOpen parameter for the namespace. Unfortunately I don't any experience with XML namespaces and their usage.

Any help is much appreciated!


Share this post

Link to post
Share on other sites

What you have is an un-named default namespace. You have to give it a name to be used in the XPath references:

#include <Array.au3>
#include <_XMLDomWrapper.au3>
$debugging = True
$sXmlNS = '"urn:schemas-fujitsu-siemens-com:software-preload"'
$inputFile = @ScriptDir & "\Test1.xml"
If FileExists($inputFile) Then
_XMLFileOpen($inputFile, 'xmlns=' & $sXmlNS)
If Not @error Then
  $objDoc.setProperty("SelectionNamespaces", 'xmlns:MyNS=' & $sXmlNS)
  $aTemp = _XMLGetValue("/MyNS:Systems/MyNS:System/MyNS:SystemIdentification/MyNS:MACAddresses/MyNS:MACAddress")
  MsgBox(0, "Error", "Error opening File: " & @error)


Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...