Jump to content

XML DOM wrapper (COM)


eltorro
 Share

Recommended Posts

  • Moderators

I'm trying to use UDF version 1.2.0.19. But somehow all the code posted in this thread ends up being invalid... Is that correct? Should that happen?

With that much information... the answer is yes :whistle:

Really... what version of AutoIt ... OS etc...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

WinXP (doesn't matter), latest AutoIT (both beta & stable)..

Try this copy that I have.

_XMLDomWrapper.zip

@eltorro

Issue with dowloading from 1st post

<br />

<b>Warning</b>: fopen(files/public_downloads/_XMLDomWrapper.au3.dlcnt) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Permission denied in <b>/var/www/web1/web/fileman/index.php</b> on line <b>309</b><br />

<br />

<b>Warning</b>: fwrite(): supplied argument is not a valid stream resource in <b>/var/www/web1/web/fileman/index.php</b> on line <b>311</b><br />

<br />

<b>Warning</b>: fclose(): supplied argument is not a valid stream resource in <b>/var/www/web1/web/fileman/index.php</b> on line <b>313</b><br />

; =======================================================================

; Project Manager 3.0 Preprocessed - Date 25:04:2007 Time 14:28

; =======================================================================

and rest of lines of code etc. , and then script is cut off as being incomplete.

Edit:

Removed attachment to confirm that eltorro has fixed the link for download at the 1st post. My version attached was an earlier verson so please update. Thanks to eltorro for prompt action in fixing the download. :whistle:

Edited by MHz
Link to comment
Share on other sites

Please try the download links again. A server upgraded changed permissions( ownership actually) on the folders. I tested the download using google as a proxy and all the tests were good.

Link to comment
Share on other sites

First, thanks for this great work.

I'm having trouble with getting attributes with _XMLGetAttrib. Using autoit 3.2.5 and 3.2.4.9. XMLUDFVer 1.0.3.68

The example script can't load attributes.. this is the output from SciTE:

Debug = True
Get Attrib length= 0
Attribute x not found for: Settings/Position
No qualified items found
Get Attrib length= 0
Attribute y not found for: Settings/Position
No qualified items found
Get Attrib length= 0
Attribute w not found for: Settings/Position
No qualified items found
Get Attrib length= 0
Attribute h not found for: Settings/Position
No qualified items found
GetValue>$strXPath:Settings/State
GetValue>$strXPath:Settings/Edit
GetValue>$strXPath:Settings/Tab
GetValue>$strXPath:Settings/List
GetValue>$strXPath:Settings/ListView
GetValue>$strXPath:Settings/ListView
GetValue>$strXPath:Settings/Radio1
GetValue>$strXPath:Settings/Radio2
GetValue>$strXPath:Settings/UpDown
GetValue>$strXPath:Settings/Slider
GetValue>$strXPath:Settings/Input
GetValue>$strXPath:Settings/Check
GetValue>$strXPath:Settings/Tv1
GetValue>$strXPath:Settings/Tv2
4 40 , Item_0 , -1
1 , Item_1 , 80
2 , Item_2 , 80
3 , Item_3 , 80
4 , Item_4 , 80
Node Selected
Exitloop
Error creating child node: Items
Tv2 does not exist.

>Exit code: 0   Time: 3.342

The XML writing seems to work fine, as this is in the XmlExample.au3.xml:

<?xml version="1.0"?>
<Settings>
<Position x="438" y="275" w="406" h="425"/>
<State>15</State>
<Tab/>
<Edit>
  Sample Edit Control</Edit>
<List>1</List>
<ListView/>
<Radio1>1</Radio1>
<Radio2>4</Radio2>
<UpDown>42</UpDown>
<Slider>30</Slider>
<Input>Sample Input Box</Input>
<Check>1</Check>
<Tv1>46</Tv1>
<Tv2/>
</Settings>

Running Win2K S

Also, does this still require beta autoit?

thanks for any help.

Link to comment
Share on other sites

Hmm, I can't seem to edit, but I've made some progress in solving this.

It looks like the problem comes from the inconsistency in the use of $objDoc.documentElement.selectNodes VS $objDoc.selectNodes

(see _XMLGetAttrib VS _XMLSetAttrib) one is referenced to the root node and the other isn't. Deleting the documentElement root reference from GetAttrib solves the attrib problem.

Is this on purpose, or should this root reference be standardised? thanks.

Link to comment
Share on other sites

The problem is a that the the lines should using a backslash at the start ( $var = _XMLGetAttrib("/Settings/Position", "h") ).

With all the updates to the wrapper, the example is broken for the moment.

Link to comment
Share on other sites

Link to comment
Share on other sites

Here is an updated multi-file capable wrapper based on the new wrapper code. Perhaps, since the multi-file selection is optional, this can be the new base and no code fork MDI necessary.

Here It Is The function descriptions are not updated.

a few notes:

New file creation and access, note CreateFile does not initiate an objDoc, you must re-open it with FileOpen:

$outfile=_XMLCreateFile(@ScriptDir & "\" & $myfilename, "Root", True)
    if $outfile = -1 then Exit 1
    $outfile=_XMLFileOpen(@ScriptDir & "\" & $myfilename,"",3,True,1); open file into container 1
    if $outfile = -1 then Exit 2
        _XMLCreateAttrib("/Root",$AttribName, $Attribdata,1);reference file in container 1
Link to comment
Share on other sites

Getting an error :whistle:

C:\Program Files\AutoIt3\beta\Include\_XMLDomWrapper.au3(1432,34) : WARNING: $oIndex: possibly used before declaration.
    $xslProc.input = $objDoc[$oIndex]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\beta\Include\_XMLDomWrapper.au3(1432,34) : ERROR: $oIndex: undeclared global variable.
    $xslProc.input = $objDoc[$oIndex]

[acronym="I pee FREELY!"][spoiler]Hello.[/spoiler][/acronym]

Link to comment
Share on other sites

err fixed that error now another..

C:\Program Files\AutoIt3\beta\Include\_XMLDomWrapper.au3 (336) : ==> Error in expression.: 
$objNodeList = $objDoc.documentElement.selectNodes ($strXPath) 
$objNodeList = ^ ERROR

[acronym="I pee FREELY!"][spoiler]Hello.[/spoiler][/acronym]

Link to comment
Share on other sites

Link to comment
Share on other sites

Global $b = _FileSearch($scriptroot & "*.xml", 1)

Func GetSelection()
    $select = GUICtrlRead($select_list)
    $file = _XMLFileOpen($scriptroot & $select & '.xml')
    $name = _XMLGetValue('/settings/name')
    $author = _XMLGetValue('/settings/author')
EndFunc

Func GetList()
    If $b[0] > 0 Then
        For $i = 1 To $b[0]
            If $b[$i] <> "" Then
                _GUICtrlListAddItem($select_list, _Str_ExtractFile($b[$i]))
            EndIf
        Next
    Else
        MsgBox(16, "Error", "No XML file Found!")
    EndIf
EndFunc   ;==>GetList



The Xml file:

[codebox]
[html]<?xml version="1.0"?>
<settings>
<name>Blah</name>
<author>Squizzle</author>
</settings>[/html] Edited by Squizzle

[acronym="I pee FREELY!"][spoiler]Hello.[/spoiler][/acronym]

Link to comment
Share on other sites

Without your whole script, it is hard to find where your bug lies. Without a working script that generates the bug you describe, I have no way to help you.

With the snippet you provided I can open and read both the name and the author without error.

#include <Z:\fileman\_XMLDomWrapper.au3>
;Global $b = _FileSearch($scriptroot & "*.xml", 1)
Global $b = "squizzle.xml"
GetSelection()
Func GetSelection()
    ;$select = GUICtrlRead($select_list)
    ;$file = _XMLFileOpen($scriptroot & $select & '.xml')
     _XMLFileOpen($B)
    $name = _XMLGetValue('/settings/name')
    $author = _XMLGetValue('/settings/author')
     ConsoleWrite($name[1]&@LF)
     ConsoleWrite($author[1]&@LF)
EndFunc

;~ Func GetList()
;~     If $b[0] > 0 Then
;~         For $i = 1 To $b[0]
;~             If $b[$i] <> "" Then
;~                 _GUICtrlListAddItem($select_list, _Str_ExtractFile($b[$i]))
;~             EndIf
;~         Next
;~     Else
;~         MsgBox(16, "Error", "No XML file Found!")
;~     EndIf
;~ EndFunc   ;==>GetList

My guess would be that the file failed to open therefore the wrong type of object does not exist. Check the return of _XMLFileOpen and _XMLError().

Edited by eltorro
Link to comment
Share on other sites

Added an object check to each applicable function.

When an xml file failed to open, the resulting object created to hold the document still existed with an empty document.

Instead, the object is now released from memory. Therefore the object no longer exists.

Update _XMLDomWrapper now available.

Please see first post.

Link to comment
Share on other sites

Not sure but I was working with the stable AutoItv3 then went to Beta for the XMLDOMWrapper to work and things got messy after that. But I'll work on it, trial and error.

[acronym="I pee FREELY!"][spoiler]Hello.[/spoiler][/acronym]

Link to comment
Share on other sites

Which beta version are you using? Can you post the complete script?

Link to comment
Share on other sites

Uinstalled stable autoitv3 and installed beta over everything now it works but im getting a -1 for the controls that use

_XMLGetValue('')

Since the -1 is the return value I am guessing the problem area lies:

Func _XMLGetValue($strXPath)
    If not IsObj($objDoc) then
        _XMLError("No object passed to function _XMLGetValue")
        Return SetError(1,3,-1)
    EndIf
    Local $objNodeList, $arrResponse[1], $objNodeChild, $xmlerr
    While @error = 0
        _DebugWrite("GetValue>$strXPath:"&$strXPath)
        $objNodeList = $objDoc.documentElement.selectNodes ($strXPath)
        If $objNodeList.length > 0 Then
            _DebugWrite("GetValue list length:" & $objNodeList.length)
            For $objNode In $objNodeList
                If $objNode.hasChildNodes () = False Then
                    _XMLArrayAdd($arrResponse, $objNode.nodeValue)
                Else
                    For $objNodeChild In $objNode.childNodes ()
                        If $objNodeChild.nodeType = $NODE_CDATA_SECTION Then
                            _XMLArrayAdd($arrResponse, $objNodeChild.data)
                            _DebugWrite("GetValue>CData:" & $objNodeChild.data)
                        ElseIf $objNodeChild.nodeType = $NODE_TEXT Then
                            _XMLArrayAdd($arrResponse, $objNodeChild.Text)
                            _DebugWrite("GetValue>Text:" & $objNodeChild.Text)
                        EndIf
                    Next
                EndIf
            Next
;;;;;;;;;;;;;;;HERE :(
            $arrResponse[0] = UBound($arrResponse) - 1
            Return $arrResponse
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        Else
            $xmlerr = @CRLF & "No matching node(s)found!"
            Return SetError(1,0,-1)
            ExitLoop
        EndIf
    WEnd
    _XMLError("Error Retrieving: " & $strXPath & $xmlerr)
    SetError(1)
    Return -1
EndFunc   ;==>_XMLGetValue

[acronym="I pee FREELY!"][spoiler]Hello.[/spoiler][/acronym]

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...