Jump to content

_ArrayDisplay


Recommended Posts

Hi,

I've looked thru the help file and searched this forum to try and figure out how to get $test1, $test2, and $test3 to display in _ArrayDisplay but I can't figure it out.

How can I get $test1, $test2, and $test3 to display in _ArrayDisplay at the same time?

#include <_XMLDOMWrapper.au3>
#include <Array.au3>

Local $cTests, $splitTests1, $splitTests2

; Open file
$sXML = @ScriptDir & "\ArrayDisplayTest.xml"
If _XMLFileOpen($sXML,"",-1) = -1 Then
    ConsoleWrite("can´t open file!" & @CRLF)
    Exit
EndIf

; Get count of item nodes in menu
$iItems = _XMLGetNodeCount("/test/tests/name")

For $i = 1 To $iItems -1
    $test1 = _XMLGetAttrib("/test/tests/name[" & $i & "]","record")
    $test2 = _XMLGetAttrib("/test/tests/name[" & $i & "]","results")
    $test3 = _XMLGetAttrib("/test/tests/name[" & $i & "]","spare")  
    
    $Tests = $test1 & "," & $test2 & "," & $test3 & ";"
    $cTests = $cTests & $Tests      
Next
$splitTests1 = StringSplit($cTests, ";")

;Will not display all test in _ArrayDisplay
For $Ti = 1 To UBound($splitTests1) -1
    $splitTests2 = StringSplit($splitTests1[$Ti], ",")  
Next
_ArrayDisplay($splitTests2, "Array2 ", -1, 1)

<test>
  <tests>       
    <name record="record1" results="results1" spare="spare1" /> 
    <name record="record2" results="results2" spare="spare2" /> 
    <name record="record3" results="results3" spare="spare3" />
    <name record="record4" results="results4" spare="spare4" />
    <name record="record5" results="results5" spare="spare5" />
  </tests>  
</test>

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

Arrays do not concatenate by "&". There is an _ArrayConcatenate() function though.

:mellow:

Edit: Oops. True, but unhelpful -- I thought _XMLGetAttrib() returned an array like most of the _XMLGet* functions.

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

Something like this?

#include "_XMLDomWrapper.au3"
#include <Array.au3>
Global $test
Global $sFile = @ScriptDir & "\test.xml"
For $s = 1 To HowManyNodes("test/tests/name")
    $test &= ReadXMLAttrib("tests/name[@record='record" & $s & "']", "record") & " "
    $test &= ReadXMLAttrib("tests/name[@record='record" & $s & "']", "results") & " "
    $test &= ReadXMLAttrib("tests/name[@record='record" & $s & "']", "spare") & @LF
Next
$array = StringSplit($test, @LF)
_ArrayPop($array)
_ArrayDisplay($array)

Func ReadXMLAttrib($path, $atribut)
    _XMLFileOpen($sFile)
    Local $a = _XMLGetAttrib($path, $atribut)
    Return $a
EndFunc   ;==>ReadXMLAttrib

Func HowManyNodes($path)
    _XMLFileOpen($sFile)
    Local $a = _XMLGetNodeCount($path)
    Return $a
EndFunc   ;==>HowManyNodes

Those functions I've included in a script to ease my work with xml files.

[edit] I've edited my post because I use a modified version of _XMLDomWrapper, but now it should work for you

Edited by taietel
Link to comment
Share on other sites

;~ #include <_XMLDOMWrapper.au3> ; dont have this include
#include <Array.au3>

Local $cTests, $splitTests1, $splitTests2

; Open file
;~ $sXML = @ScriptDir & "\ArrayDisplayTest.xml"
;~ If _XMLFileOpen($sXML,"",-1) = -1 Then
;~     ConsoleWrite("can´t open file!" & @CRLF)
;~     Exit
;~ EndIf

; Get count of item nodes in menu
;~ $iItems = _XMLGetNodeCount("/test/tests/name")

For $i = 1 To 5
;~     $test1 = _XMLGetAttrib("/test/tests/name[" & $i & "]","record")
    $test1 = "record" & $i
;~     $test2 = _XMLGetAttrib("/test/tests/name[" & $i & "]","results")
    $test2 = "results" & $i
;~     $test3 = _XMLGetAttrib("/test/tests/name[" & $i & "]","spare")
    $test3 = "spare"  & $i

    $Tests = $test1 & "," & $test2 & "," & $test3 & ";"
    $cTests = $cTests & $Tests
Next
$splitTests1 = StringSplit(StringTrimRight($cTests, 1), ";",2) ; StringTrimRight to remove the extra ; from the end
;Will not display all test in _ArrayDisplay

$aNoOfRec = StringSplit($splitTests1[0],",", 2)
Local $splitTests2[UBound($splitTests1)][UBound($aNoOfRec)]
For $Ti = 0 To UBound($splitTests1)-1
    $aTempSplit = StringSplit($splitTests1[$Ti], ",",2) ; you where overwriting $splitTests2
    For $i = 0 To UBound($aTempSplit)-1 Step 1
        $splitTests2[$Ti][$i] = $aTempSplit[$i]
    Next
Next
_ArrayDisplay($splitTests2, "Array2 ", -1, 1)

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Tested this while playing with a modification to __XMLGetAllAttrib():

#include <_XMLDOMWrapper.au3>
#include <Array.au3>

$debugging = True ; Internal to _XMLDOMWrapper.au3

Global $sXML, $iItems, $aRET

$sXML = @ScriptDir & "\Test1.xml"
If _XMLFileOpen($sXML, "", -1) = -1 Then
    ConsoleWrite("can´t open file!" & @CRLF)
    Exit
EndIf

$iItems = _XMLGetNodeCount("/test/tests/name")
For $i = 1 To $iItems
    $aRET = __XMLGetAllAttrib("/test/tests/name[" & $i & "]")
    _ArrayDisplay($aRET, $i & ": $aRET")
Next


;===============================================================================
; Function Name:    __XMLGetAllAttrib
; Description:      Get all XML Field(s) attributes based on XPath input from root node.
; Parameter(s):     $strPath  =  Xpath to node
; Syntax:           _XMLGetAllAttrib($strPath)
; Author(s):        Stephen Podhajecki <gehossafats@netmdc.com>
;                   Modified by:  PsaltyDS at autoitscript.com  --  06/16/2010
; Return Value(s)   2D array of attrib names and values (number of items is in [0][0]
;                   Failure returns -1 and @error = 1, see @extended for details
;===============================================================================
Func __XMLGetAllAttrib($strXPath)
    If Not IsObj($objDoc) Then
        _XMLError("No object passed to function _XMLGetAllAttrib")
        Return SetError(1, 0, -1)
    EndIf

    Local $objNodeList, $objQueryNodes, $objNode, $arrResponse[1][2] = [[0, ""]]

    $objQueryNodes = $objDoc.selectNodes($strXPath)
    If $objQueryNodes.length > 0 Then
        For $objNode In $objQueryNodes
            $objNodeList = $objNode.attributes
            If ($objNodeList.length) Then
                $arrResponse[0][0] = $objNodeList.length
                ReDim $arrResponse[$objNodeList.length + 1][2]
                For $i = 0 To $objNodeList.length - 1
                    $arrResponse[$i + 1][0] = $objNodeList.item($i).nodeName
                    $arrResponse[$i + 1][1] = $objNodeList.item($i).Value
                Next
            Else
                _XMLError("No Attributes found for node")
                Return SetError(1, 2, -1)
            EndIf
        Next
        Return $arrResponse
    Else
        _XMLError("No nodes matched query for:  " & $strXPath & @CRLF)
        Return SetError(1, 1, -1)
    EndIf
EndFunc   ;==>__XMLGetAllAttrib

The modified __XMLGetAllAttrib() returns a simple 2D array of results.

Assembling the results as desired is left to the user.

:mellow:

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

Thanks for all your help but the scripts are not excatly what I'm needing.

I would like to run a For Next statement to collect all the xml name record, results, and spare. Then have the _ArrayDisplay run once displaying the data like the example below.

Row Col0     Col1      Col2
[0] record1  results1  spare1
[1] record2  results2  spare2
[2] record3  results3  spare3
[3] record4  results4  spare4
[4] record5  results5  spare5

Thanks for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

You mean merge multiple array's into one. But in the second dimension?

Yes, I think that is correct.

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

MvGulik,

I added this to the top of your script and I'm getting a blank _ArrayDisplay.

#include <_XMLDOMWrapper.au3>

Local $cTests, $splitTests1, $splitTests2

; Open file
$sXML = @ScriptDir & "\ArrayDisplayTest.xml"
If _XMLFileOpen($sXML,"",-1) = -1 Then
    ConsoleWrite("can´t open file!" & @CRLF)
    Exit
EndIf

; Get count of item nodes in menu
$iItems = _XMLGetNodeCount("/test/tests/name")

For $i = 1 To $iItems -1
    $aArray1 = _XMLGetAttrib("/test/tests/name[" & $i & "]","record")
    $aArray1 = _XMLGetAttrib("/test/tests/name[" & $i & "]","results")
    $aArray1 = _XMLGetAttrib("/test/tests/name[" & $i & "]","spare")        
Next

Thanks for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

I apologize. I did not change your script I only added my script to yours like this:

#include <Array.au3>
#include <_XMLDOMWrapper.au3>

Local $cTests, $splitTests1, $splitTests2

; Open file
$sXML = @ScriptDir & "\ArrayDisplayTest.xml"
If _XMLFileOpen($sXML,"",-1) = -1 Then
    ConsoleWrite("can´t open file!" & @CRLF)
    Exit
EndIf

; Get count of item nodes in menu
$iItems = _XMLGetNodeCount("/test/tests/name")

For $i = 1 To $iItems -1
    $aArray1 = _XMLGetAttrib("/test/tests/name[" & $i & "]","record")
    $aArray1 = _XMLGetAttrib("/test/tests/name[" & $i & "]","results")
    $aArray1 = _XMLGetAttrib("/test/tests/name[" & $i & "]","spare")        
Next


Func MAIN()

    Local $aArray1[2] = [1, 2]
    Local $aArray2[4] = [3, 4, 5, 6]
    Local $aDelim[4] = ['|', '|', '|', '|']
    Local $aArray3[3] = [7, 8, 9]

    Local $aArrayMerge = $aArray1
    Array_MergeField_2D($aArrayMerge, $aArray2)
    Array_MergeField_2D($aArrayMerge, $aDelim)
    Array_MergeField_2D($aArrayMerge, $aArray3)

    Local $aTmp = $aArrayMerge
    Array_MergeField_2D($aArrayMerge, $aDelim)
    Array_MergeField_2D($aArrayMerge, $aTmp)

    _ArrayDisplay($aArrayMerge)

    Return
EndFunc

Func Array_MergeField_2D(ByRef $aTarget, Const ByRef $aSource)

    If Not (IsArray($aTarget) And IsArray($aSource)) Then Return SetError(1) ;; block none array types.
    If UBound($aTarget, 0) > 2 Or UBound($aSource, 0) > 2 Then Return SetError(2) ;; block more than 2 dimentional array's
;~  ;; differand lenght arrays not supported. (needs additional code)
;~  If UBound($aTarget, 1) <> UBound($aSource, 1) Then Return SetError(3) ;; block differant size(dim1) array's
    Local Const $NoChange = UBound($aSource, 2) ;; ERM ... no sure about this. blocking it. (same array as target and source parameter)

    ;; allouw for single dimentional target array.
    If UBound($aTarget, 0) = 1 Then
        Local $aTmp[UBound($aTarget, 1)][1]
        For $i = 0 To UBound($aTarget, 1) - 1
            $aTmp[$i][0] = $aTarget[$i]
        Next
        $aTarget = $aTmp
        If not (UBound($aSource, 2) = $NoChange) Then Return SetError(4)
        $aTmp = ''
    EndIf

    ;; allow for differant lenght array's. (could be done without additional redim -> speed with large arrays)
    If UBound($aTarget, 1) < UBound($aSource, 1) Then ReDim $aTarget[UBound($aSource, 1)][UBound($aTarget, 2)]

    Local $iFieldOffset = UBound($aTarget, 2)
    If UBound($aSource, 0) = 1 Then ;; single dimentional source array.
        ReDim $aTarget[UBound($aTarget, 1)][UBound($aTarget, 2) + 1]
        For $i = 0 To UBound($aSource, 1) - 1
            $aTarget[$i][$iFieldOffset] = $aSource[$i]
        Next
    Else ;; 2 dimentional source array.
        ReDim $aTarget[UBound($aTarget, 1)][UBound($aTarget, 2) + UBound($aSource, 2)]
        If not (UBound($aSource, 2) = $NoChange) Then Return SetError(4)
        For $j = 0 To UBound($aSource, 2) - 1
            For $i = 0 To UBound($aSource, 1) - 1
                $aTarget[$i][$iFieldOffset + $j] = $aSource[$i][$j]
            Next
        Next
    EndIf

    Return
EndFunc

MAIN()
If @error Then Exit @error

My xml file:

<test>
  <tests>       
    <name record="record1" results="results1" spare="spare1" /> 
    <name record="record2" results="results2" spare="spare2" /> 
    <name record="record3" results="results3" spare="spare3" />
    <name record="record4" results="results4" spare="spare4" />
    <name record="record5" results="results5" spare="spare5" />
  </tests>  
</test>

Thanks for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

MvGulik,

Thank you for your help the script works excatly the way I need it to.

Still learning how to write code,

jfcby

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

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