Jump to content

xml formatted data help

Recommended Posts


hi guys

 i have   a problem  with a  script  i have  this  array

Row|Col 0|Col 1
[1]|<CategoryName>|Cellulari e smartphone
[3]|<CategoryParentName>|Telefonia fissa e mobile
[6]|<CategoryName>|Cover e custodie
[9]|<CategoryParentName>|Telefonia fissa e mobile
[10]|<CategoryParentName>|Accessori cellulari e palmari
[13]|<CategoryName>|Cellulari: componenti
[15]|<CategoryParentName>|Telefonia fissa e mobile
[18]|<CategoryName>|Cavi e adattatori
[21]|<CategoryParentName>|Telefonia fissa e mobile
[22]|<CategoryParentName>|Accessori cellulari e palmari
[25]|<CategoryName>|Caricabatterie e dock
[28]|<CategoryParentName>|Telefonia fissa e mobile
[29]|<CategoryParentName>|Accessori cellulari e palmari
[32]|<CategoryName>|Proteggi schermo
[35]|<CategoryParentName>|Telefonia fissa e mobile
[36]|<CategoryParentName>|Accessori cellulari e palmari
[42]|<CategoryParentName>|Telefonia fissa e mobile
[43]|<CategoryParentName>|Accessori cellulari e palmari
[53]|<CategoryParentName>|Paesaggistiche italiane
[57]|<CategoryName>|Altro orologi e gioielli
[59]|<CategoryParentName>|Orologi e gioielli
[62]|<CategoryName>|Vivavoce per auto
[65]|<CategoryParentName>|Telefonia fissa e mobile
[66]|<CategoryParentName>|Accessori cellulari e palmari

i want extract  data  in this mode:   http://it.tinypic.com/r/14xf21w/9

for  do that  i  create  3  function

Func _eBay_Category_XML_clean($aXML_Dirty)
    Local $DoCont = 0
    Local $ContArr = 0
    Local $sPath_tempEND = @ScriptDir & "\TEMP\END.txt"
    Local $sPath_tempStart = @ScriptDir & "\TEMP\START.txt"
    Local $categoriID
    Local $categoriNAm
    Local $CategoryParentID
    Local $CategoryParentName
    Local $ilinee = 1
    Local $mm = 0
    Local $zz = 0
    Local $cc = 0
    Local $ccPID = 0
    ;If FileExists($sPath_tempEND) Then
    ;   FileDelete($sPath_tempEND)
    If FileExists($sPath_tempStart) Then
        If $aXML_Dirty[$DoCont][0] = "<CategoryID>" Then
            $categoriID = $aXML_Dirty[$DoCont][1]
            _True_write_File($sPath_tempStart, $categoriID & "_")
            $mm = 0
            $zz = 0
            ;$ContArr += 1

        If $aXML_Dirty[$DoCont][0] = "<CategoryName>" Then
            $categoriNAm = $aXML_Dirty[$DoCont][1]
            _True_write_File_IN_Line($sPath_tempStart, $categoriNAm & "_")
            ;$ContArr += 1

        If $aXML_Dirty[$DoCont][0] = "<PercentItemFound>" Then
            If $cc = 0 Then
                _True_write_File($sPath_tempStart, @CRLF)
                ;$zz = 0
                $mm = 0
                $zz = 0
                $DoCont -= ($ccPID+1)

            If $aXML_Dirty[$DoCont][0] = "<CategoryParentID>" Then
                $CategoryParentID = $aXML_Dirty[$DoCont][1]
                $ccPID += 1
                If $zz = 0 Then
                    _True_write_File_IN_Line($sPath_tempStart, "__+__>" & $CategoryParentID & "_")
                    $zz = 2

            If $aXML_Dirty[$DoCont][0] = "<CategoryParentName>" Then
                $CategoryParentName = $aXML_Dirty[$DoCont][1]
                If $mm = 0 Then
                    _True_write_File_IN_Line($sPath_tempStart, "__+__>" & $CategoryParentName)
                    $mm = 1
                    $cc = 1
            ;$ContArr += 1
            ;If $aXML_Dirty[$DoCont][0] = "<PercentItemFound>" Then
            ;   $mm = 0
            ;   $zz = 0
            ;   $DoCont -= $ccPID
            ;$ContArr += 1
        ;MsgBox(0, '', 'son qui 91')
        $DoCont += 1
    Until $DoCont = UBound($aXML_Dirty)

EndFunc   ;==>_eBay_Category_XML_clean

Func _True_write_File($sFilePath, $sDataWrite)

    $file = FileOpen($sFilePath, 1)
    FileWrite($file, $sDataWrite & @CRLF)

EndFunc   ;==>_True_write_File

Func _True_write_File_IN_Line($sPath_tempStart, $sData)

    Local $aArray = FileReadToArray($sPath_tempStart)
    Local $last = UBound($aArray)
    Local $sFileRead = $aArray[$last - 1]

    Local $stop = $last - 2
    Local $hFileOpen = FileOpen($sPath_tempStart, $FO_OVERWRITE)
    For $I = 0 To $stop
        FileWrite($hFileOpen, $aArray[$I] & @CRLF)
    FileWrite($hFileOpen, $sFileRead & $sData)

EndFunc   ;==>_True_write_File_IN_Line

but  i  have  some problem one of  this  is not  reconstruct  in txt like  i want  :D

and  second  give me  always 

"E:\_GESTIONALE_NEW\include\GUI_Configure.au3" (42) : ==> Variable subscript badly formatted.:
If $aXML_Dirty[$DoCont][0] = "<CategoryID>" Then
If $aXML_Dirty[^ ERROR
->12:41:16 AutoIt3.exe ended.rc:1

some one  can help me ?? , thankz  at all


Share this post

Link to post
Share on other sites

did you try my    XML.au3 UDF    ?


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-31

Share this post

Link to post
Share on other sites

o thankz  @mLipok i  just  try  to use  it  :)


Share this post

Link to post
Share on other sites

i  start  to see  the  xml udf  , but notwork give me some error 

"E:\_GESTIONALE_NEW\include\GUI_Configure.au3"(28,73) : error: XML_My_ErrorParser(): undefined function.
            MsgBox(0, '_XML_CreateDOMDocument @error:', XML_My_ErrorParser(@error)

i look your  example  yout  think for my  xml

<?xml version="1.0" encoding="UTF-8"?>
<GetSuggestedCategoriesResponse xmlns="urn:ebay:apis:eBLBaseComponents"

is possible to use ??  becouse  i must mix  like  in schema


now  i must go  but  soon i  look much  better  , thankz  at  all again for  help  and  support




Share this post

Link to post
Share on other sites

This is the best I can offer, if it doesn't fit your needs then I give up  :)

#Include <Array.au3>

$txt = FileRead("file.xml")
$tmp = StringRegExp($txt, '(?is)<Category>(.+?)</Category>', 3)

Local $res[100][4] = [["<CategoryID>", "<CategoryName>", "<CategoryParentID>", "<CategoryParentName>"]]
$n = 1

For $i = 0 To UBound($tmp) - 1
    $aCategory = StringRegExp($tmp[$i], '<Category(?:ID|Name)>([^<]+)', 3)
    $aParentsID = StringRegExp($tmp[$i], "<CategoryParentID>([^<]+)", 3)
    $aParentsName = StringRegExp($tmp[$i], "<CategoryParentName>([^<]+)", 3)
    For $j = 0 To UBound($aParentsID) - 1
       $res[$n][0] = $aCategory[0]
       $res[$n][1] = $aCategory[1]
       $res[$n][2] = $aParentsID[$j]
       $res[$n][3] = $aParentsName[$j]
       $n += 1
Redim $res[$n][4]
_ArrayDisplay($res, "sorted by categoryID")

; reorder the array, sort by parent name

_ArraySort($res, 0, 0, 0, 3)
Local $res2[UBound($res)][4] 
For $i = 0 To UBound($res) - 1
   $res2[$i][0] = $res[$i][2]
   $res2[$i][1] = $res[$i][3]
   $res2[$i][2] = $res[$i][0]
   $res2[$i][3] = $res[$i][1]
_ArrayDisplay($res2, "sorted by CategoryParentName")


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