Jump to content

Counting XML Data and Writing to File


Recommended Posts

Hi, I'm totally new to AutoIT and need help.

I am successfully gathering data from an XML file and writing the information to a txt file. Currently my output to the txt file from the XML views as:

Agency: John

Agency: Jack

Agency: Pam

Agency: Pam

Agency: John

Agency: Cindy

However, I would like to sort my output to view as:

Agency: John = 2

Agency: Jack = 1

Agency: Pam = 2

Agency: Cindy = 1

I thought maybe using the _ArrayUnique would work, however I have failed to be successful.

Here is how I am writing to the txt file currently:

Func OKPressed()

    ;XML file to open
    $sXMLFile = $localxmlfile

    $result = _XMLFileOpen($sXMLFile)
    If $result = 0 then Exit
    
    $rootPath = "//registration"
    $file = FileOpen("test.txt", 1)
    
    If GUICtrlRead($box1) = $GUI_CHECKED Then
    ;Write all Student Agency names to textfile (Attributes are case sensitive)
    $studentAgencyArray = _XMLGetChildNodes($rootPath)
    For $W = 1 to $studentAgencyArray[0]
        $WNode = $studentAgencyArray[$W]
        $studentAgencyPath = $rootPath & "/" & $WNode & "[" & $W & "]"
        FileWrite($file, "Agency" & ": " & _XMLGetAttrib ($studentAgencyPath, "agency") & @CRLF & @CRLF)   
        Next
    EndIf   
Exit
EndFunc
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...