Jump to content

XML DOM wrapper (COM)


eltorro
 Share

Recommended Posts

I am trying to extract a UserName of a created user... it has some sort of namespace thing that I just don't get...

Lar.

Here you go, this will dump all account info to the console:

#include <_XMLDomWrapper.au3>
#include <Array.au3>

$sXMLFile = "Autounattend.xml"

$result = _XMLFileOpen($sXMLFile, 'xmlns:un="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"')
If $result = 0 Then Exit

;Set root path to LocalAccounts area of xml
$path = '//un:unattend/un:settings[@pass="oobeSystem"]/un:component[@name="Microsoft-Windows-Shell-Setup"]/un:UserAccounts/un:LocalAccounts'

;Retrieve count of LocalAccount nodes
$accountsArray = _XMLSelectNodes($path & '/*')

If IsArray($accountsArray) Then
    ;_ArrayDisplay($accountsArray)
    
    ;Loop through all LocalAccount nodes
    For $X = 1 to $accountsArray[0]
        ConsoleWrite("LocalAccount " & $X & @CRLF)
        
        ;Count subnodes in LocalAccount (should have Password, Description, DisplayName, Group, Name)
        $nodesArray = _XMLSelectNodes($path & '/un:LocalAccount/*')

        ;Dump all LocalAccount info (skip Password since it has subnodes)
        If IsArray($nodesArray) Then    
            For $Y = 1 to $nodesArray[0]
                If $nodesArray[$Y] <> "Password" Then
                    ConsoleWrite($nodesArray[$Y] & ": " & _GetFirstValue($path & "/un:LocalAccount[" & $X & "]/un:" & $nodesArray[$Y]) & @CRLF)
                EndIf
            Next
        EndIf
        ConsoleWrite(@CRLF)
    Next
EndIf

;_XMLGetValue returns an array (not sure why) this will return the first element
Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc

Sample XML used from here:

http://www2.uiowa.edu/clas/it/support/Wind...tendedVista.htm

Edited by weaponx
Link to comment
Share on other sites

Hi AutoIt and XML gurus

I'm trying to process the return envelope from a SOAP request.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <FolderResponse xmlns="http://microsoft.com/workbench/store">
      <FolderResult>
        <Documents Count="3">
          <Document DocumentID="1" />
          <Document DocumentID="2" />
          <Document DocumentID="3" />
        </Documents>
      </FolderResult>
    </FolderResponse>
  </soap:Body>
</soap:Envelope>

I'm trying to access all "DocumentID". But _XMLSelectNodes() can't process past <FolderResponse xmlns="http://microsoft.com/workbench/store">

Here is my AutoIt code:

#Include <Array.au3>
#Include <_XMLDomWrapper.au3>

Local $sFile = "C:\XMLFile1.xml"
If FileExists($sFile) Then
    Local $ret = _XMLFileOpen ($sFile, 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"') 
    Local $sNodes = _XMLSelectNodes('//soap:Envelope/soap:Body/FolderResponse[@xmlns="http://microsoft.com/workbench/store"]/*')
    _ArrayDisplay($sNodes, "$sNodes")
EndIf

Then it works fine.

Why is _XMLSelectNodes() failing on [@xmlns="http://microsoft.com/workbench/store"] ?

Is it something wrong in my syntax? or is it somthing that the XML DOM Wrapper can't do?

Thanks

uteotw

Edited by uteotw
Link to comment
Share on other sites

The first thing I see as that the second namespace in your script is a broken link:

http://microsoft.com/workbench/store

True, but does the XML DOM Wrapper try to access that url when processing xmlns attribute?

By the way, I'm not the one owning the system generating the XML.

I've just found out that if it were

<soap:FolderResponse xmlns="http://microsoft.com/workbench/store">

then

Local $sNodes = _XMLSelectNodes('//soap:Envelope/soap:Body/soap:FolderResponse/*')

would work

So, how can I declare before that not all the nodes use the "soap" name space?

Edited by uteotw
Link to comment
Share on other sites

What is generating this xml? I found no evidence of that namespace ever existing:

http://web.archive.org/web/*/http://micros...workbench/store

I did a google search for "http://microsoft.com/workbench/store", "http://microsoft.com/workbench", and "FolderResponse"...nothing found.

You can make your code work by stripping: xmlns="http://microsoft.com/workbench/store"

Local $sNodes = _XMLSelectNodes('//soap:Envelope/soap:Body/FolderResponse/*')

My search for SOAP + envelope returns a lot of xml examples that don't match this at all.

Edited by weaponx
Link to comment
Share on other sites

Hi folks,

well i am kinda new and pretty much noob ;)

And sometimes i think :D:) when i see some code,...

(i should really come to the point now.... sorry i am just a girl... i love eMotes :( )

well... i have an XML-File and need a code which reads out some data of the XML-File and

put this data into variables (so i stupid one are able to work with it :"> )

The XML-File looks like this:

<drinks order="4593">

<drink id="1" prod="534" name="Milk" oid="361" dd="be_019" og_id="Drink" gid="Medium" avb="1"/>

<drink id="2" prod="635" name="Coffee" oid="132" dd="be_044" og_id="Drink" gid="Hot" avb="0"/>

<drink id="3" prod="157" name="Water" oid="173" dd="he_019" og_id="Drink" gid="Cold" avb="1"/>

</drinks>

the data i need is:

id, name, og_id, gid

and i have no idea how to make it,...

is there anyone who please help me and give me a example or something ?

(i guess i must use XML-DOM-wrapper somehow ?)

Thanks for helping,..

Br,

Andrea

Link to comment
Share on other sites

Hi, I have one more question, I have an xml file like this:

<Key KeyName="Common.TargetParty4" BarState="Indifferent" ShiftState="None" VK="F5" />
  <Key KeyName="Common.TargetSelf" BarState="Indifferent" ShiftState="None" VK="F1" />
  <Key KeyName="Common.Time1" BarState="Indifferent" ShiftState="None" Char="Undefined" />
  <Key KeyName="Common.Time30" BarState="Indifferent" ShiftState="None" Char="Undefined" />
  <Key KeyName="Common.Time5" BarState="Indifferent" ShiftState="None" Char="Undefined" />
  <Key KeyName="Pogue.Stealth" BarState="Bar5" ShiftState="None" Char="3" />
  <Key KeyName="Pogue.Ranged" BarState="Bar6" ShiftState="None" Char="-" />
  <Key KeyName="Pogue.Sinister" BarState="Bar1" ShiftState="None" Char="1" />

It has alot more nodes

I need to retrieve each first part of the "." in the KeyName.

For example, I need to retrieve the "Common" and the "Pogue" in the xml file above. There will be more than 2. :)

Link to comment
Share on other sites

@sinister I think you can figure this out on your own. The only difference from the first code I posted for you is the attribute name, you can use StringSplit to get the first part before the period.

Link to comment
Share on other sites

Hi, I have one more question, I have an xml file like this:

<Key KeyName="Common.TargetParty4" BarState="Indifferent" ShiftState="None" VK="F5" />
  <Key KeyName="Common.TargetSelf" BarState="Indifferent" ShiftState="None" VK="F1" />
  <Key KeyName="Common.Time1" BarState="Indifferent" ShiftState="None" Char="Undefined" />
  <Key KeyName="Common.Time30" BarState="Indifferent" ShiftState="None" Char="Undefined" />
  <Key KeyName="Common.Time5" BarState="Indifferent" ShiftState="None" Char="Undefined" />
  <Key KeyName="Pogue.Stealth" BarState="Bar5" ShiftState="None" Char="3" />
  <Key KeyName="Pogue.Ranged" BarState="Bar6" ShiftState="None" Char="-" />
  <Key KeyName="Pogue.Sinister" BarState="Bar1" ShiftState="None" Char="1" />

It has alot more nodes

I need to retrieve each first part of the "." in the KeyName.

For example, I need to retrieve the "Common" and the "Pogue" in the xml file above. There will be more than 2. :)

I hadn't looked back through all the post but here is a quickie example of what you want.

I don't now what weaponx posted for you before but I can't see it being much different.

#Include <_XMLDomWrapper.au3>
Local $xml = '<?xml version="1.0" encoding="utf-16"?> '  & _
'<keys> '  & _
'<Key KeyName="Common.TargetParty4" BarState="Indifferent" ShiftState="None" VK="F5" /> '  & _
'<Key KeyName="Common.TargetSelf" BarState="Indifferent" ShiftState="None" VK="F1" /> '  & _
'<Key KeyName="Common.Time1" BarState="Indifferent" ShiftState="None" Char="Undefined" /> '  & _
'<Key KeyName="Common.Time30" BarState="Indifferent" ShiftState="None" Char="Undefined" /> '  & _
'<Key KeyName="Common.Time5" BarState="Indifferent" ShiftState="None" Char="Undefined" /> '  & _
'<Key KeyName="Pogue.Stealth" BarState="Bar5" ShiftState="None" Char="3" /> '  & _
'<Key KeyName="Pogue.Ranged" BarState="Bar6" ShiftState="None" Char="-" /> '  & _
'<Key KeyName="Pogue.Sinister" BarState="Bar1" ShiftState="None" Char="1" /> '  & _
'</keys>'

_XMLLoadXML($xml)
ConsoleWrite(_XMLError()&@lf)
If @error then
    MsgBox(0,"Error",_XMLError())
    Exit
EndIf

$var= _XMLSelectNodes("keys/Key")
ConsoleWrite(_XMLError()&@lf)
If IsArray($var) Then
    For $x =1 to UBound($var)-1
        Local $aNames, $aAttribs
        ConsoleWrite($var[$x]&":")
        $sNode = StringFormat("Key[%d]",$x)
        $attrib= _XMLGetAttrib($sNode,"KeyName")
        If Not @error Then
            $pos = StringInstr($attrib,".")
            If $pos Then
                $prefix = StringLeft($attrib,StringInstr($attrib,".")-1)
                ConsoleWrite($prefix&@lf)
                If $prefix = "Common" or $prefix ="Pogue" Then
                    ConsoleWrite(StringFormat("Node [%d] has prefix %s\n",$x,$prefix))
                EndIf
            EndIf
        EndIf
    Next
EndIf
$objDoc=0
Link to comment
Share on other sites

Hi AutoIt and XML gurus

I'm trying to process the return envelope from a SOAP request.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <FolderResponse xmlns="http://microsoft.com/workbench/store">
      <FolderResult>
        <Documents Count="3">
          <Document DocumentID="1" />
          <Document DocumentID="2" />
          <Document DocumentID="3" />
        </Documents>
      </FolderResult>
    </FolderResponse>
  </soap:Body>
</soap:Envelope>

I'm trying to access all "DocumentID". But _XMLSelectNodes() can't process past <FolderResponse xmlns="http://microsoft.com/workbench/store">

Here is my AutoIt code:

#Include <Array.au3>
#Include <_XMLDomWrapper.au3>

Local $sFile = "C:\XMLFile1.xml"
If FileExists($sFile) Then
    Local $ret = _XMLFileOpen ($sFile, 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"') 
    Local $sNodes = _XMLSelectNodes('//soap:Envelope/soap:Body/FolderResponse[@xmlns="http://microsoft.com/workbench/store"]/*')
    _ArrayDisplay($sNodes, "$sNodes")
EndIf

See if this is enough to get you started.

I also made some changes to the wrapper to clean up a few things pointed out to me, and some I came across myself.

newest version is 1.0.3.87

Link to comment
Share on other sites

i have a xml file

and i want to change the value of Path

hwo can i do it

<?app version="1.0.0.0"?>
<!--This is a app config file-->
<App>
  <Function Index="0" SubIndex="2">
    <Test>
      <SN>
        <Member Path="G:\Work\1.xml" />
      </SN>
      <BT>
        <Member Path="G:\Work\2.xml" />
      </BT>
      <FT>
        <Member Path="D:\3.xml" />
      </FT>
      <IMTI>
        <Member Path="G:\4.xml" />
      </IMTI>
      <BLT>
        <Member Path="G:\Work5.xml" />
      </BLT>
      <Define>
        <Member Path="G:\6.xml" />
      </Define>
    </Test>
  </Function>
</App>
[code=auto:0]


            
        

        

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


ken0137
            
            
                Posted 
                
            
        
    
    
        


ken0137
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Members
                
            
            
                
                    
                        
                            
                                
                            
                                 18
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                    (edited)
                
                
            
        
    

    

    

    
        
        
            i have a xml file 
and i want to change the value of first Path   " <Member Path="G:\Work\1.xml" />"

hwo can i do it 
<?app version="1.0.0.0"?>
<!--This is a app config file-->
<App>
  <Function Index="0" SubIndex="2">
    <Test>
      <SN>
        <Member Path="G:\Work\1.xml" />
      </SN>
      <BT>
        <Member Path="G:\Work\2.xml" />
      </BT>
      <FT>
        <Member Path="D:\3.xml" />
      </FT>
      <IMTI>
        <Member Path="G:\4.xml" />
      </IMTI>
      <BLT>
        <Member Path="G:\Work5.xml" />
      </BLT>
      <Define>
        <Member Path="G:\6.xml" />
      </Define>
    </Test>
  </Function>
</App>
Edited by ken0137
Link to comment
Share on other sites

Link to comment
Share on other sites

i have nothing

eltorro,your xml udf can"t download

the link disabled

i just want to kown which func could do it

No the link not disabled.

I just tested it through a proxy server and It worked fine for me.

Try again. If you still have difficulty, post back.

This should be the syntax and the function you need.

_XMLSetAttribute("/App/Function/Test/SN/Member","Path","G:\New.path")

I have not tested it with you xml.

Link to comment
Share on other sites

i com form china ,and the link is disable

i use a proxy ,is ok ,

thanks your help

-----------------------

i test it

and use _XMLDomWrapper.au3(ver1.0.3.87)

but _XMLSetAttribute is not found in _XMLDomWrapper.au3

???

----------------------------------------------

are you sure is not _XMLSetAttrib("/App/Function/Test/SN/Member","Path","G:\New.path")

Edited by ken0137
Link to comment
Share on other sites

i com form china ,and the link is disable

i use a proxy ,is ok ,

thanks your help

-----------------------

i test it

and use _XMLDomWrapper.au3(ver1.0.3.87)

but _XMLSetAttribute is not found in _XMLDomWrapper.au3

???

----------------------------------------------

are you sure is not _XMLSetAttrib("/App/Function/Test/SN/Member","Path","G:\New.path")

This is correct:

_XMLSetAttrib("/App/Function/Test/SN/Member","Path","G:\New.path")

The problem is in your XML, the header is invalid.

This:

<?app version="1.0.0.0"?>

Should be:

<?xml version="1.0"?>

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...