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


Link to post
Share on other sites

did you try my    XML.au3 UDF    ?


Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 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 * Include Dependency Tree (Tool for analyzing script relations) *

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 * SciTE - Lexer for console pane

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 * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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 TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2022-03-07

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"><Timestamp>2016-08-26T19:58:26.011Z</Timestamp><Ack>Success</Ack><Version>979</Version><Build>E979_UNI_API5_18046952_R1</Build><SuggestedCategoryArray><SuggestedCategory><Category><CategoryID>9355</CategoryID><CategoryName>Cellulari e smartphone</CategoryName><CategoryParentID>15032</CategoryParentID><CategoryParentName>Telefonia fissa e mobile</CategoryParentName></Category><PercentItemFound>98</PercentItemFound></SuggestedCategory><SuggestedCategory><Category><CategoryID>20349</CategoryID><CategoryName>Cover e custodie</CategoryName><CategoryParentID>15032</CategoryParentID><CategoryParentID>9394</CategoryParentID><CategoryParentName>Telefonia fissa e mobile</CategoryParentName><CategoryParentName>Accessori cellulari e palmari</CategoryParentName></Category><PercentItemFound>1</PercentItemFound></SuggestedCategory><SuggestedCategory><Category><CategoryID>43304</CategoryID><CategoryName>Cellulari: componenti</CategoryName><CategoryParentID>15032</CategoryParentID><CategoryParentName>Telefonia fissa e mobile</CategoryParentName></Category><PercentItemFound>1</PercentItemFound></SuggestedCategory><SuggestedCategory><Category><CategoryID>58540</CategoryID><CategoryName>Proteggi schermo</CategoryName><CategoryParentID>15032</CategoryParentID><CategoryParentID>9394</CategoryParentID><CategoryParentName>Telefonia fissa e mobile</CategoryParentName><CategoryParentName>Accessori cellulari e palmari</CategoryParentName></Category><PercentItemFound>0</PercentItemFound></SuggestedCategory><SuggestedCategory><Category><CategoryID>123422</CategoryID><CategoryName>Cavi e adattatori</CategoryName><CategoryParentID>15032</CategoryParentID><CategoryParentID>9394</CategoryParentID><CategoryParentName>Telefonia fissa e mobile</CategoryParentName><CategoryParentName>Accessori cellulari e palmari</CategoryParentName></Category><PercentItemFound>0</PercentItemFound></SuggestedCategory><SuggestedCategory><Category><CategoryID>112190</CategoryID><CategoryName>Varese</CategoryName><CategoryParentID>1</CategoryParentID><CategoryParentID>914</CategoryParentID><CategoryParentID>20245</CategoryParentID><CategoryParentID>112173</CategoryParentID><CategoryParentName>Collezionismo</CategoryParentName><CategoryParentName>Cartoline</CategoryParentName><CategoryParentName>Paesaggistiche italiane</CategoryParentName><CategoryParentName>Lombardia</CategoryParentName></Category><PercentItemFound>0</PercentItemFound></SuggestedCategory><SuggestedCategory><Category><CategoryID>1383</CategoryID><CategoryName>Gadget</CategoryName><CategoryParentID>1</CategoryParentID><CategoryParentID>8894</CategoryParentID><CategoryParentName>Collezionismo</CategoryParentName><CategoryParentName>Sorpresine e gadget</CategoryParentName></Category><PercentItemFound>0</PercentItemFound></SuggestedCategory><SuggestedCategory><Category><CategoryID>11837</CategoryID><CategoryName>Altro per cura del corpo</CategoryName><CategoryParentID>26395</CategoryParentID><CategoryParentID>11838</CategoryParentID><CategoryParentName>Bellezza e salute</CategoryParentName><CategoryParentName>Cura del corpo</CategoryParentName></Category><PercentItemFound>0</PercentItemFound></SuggestedCategory><SuggestedCategory><Category><CategoryID>31519</CategoryID><CategoryName>Custodie per laptop</CategoryName><CategoryParentID>58058</CategoryParentID><CategoryParentID>31530</CategoryParentID><CategoryParentName>Informatica</CategoryParentName><CategoryParentName>Accessori laptop e desktop</CategoryParentName></Category><PercentItemFound>0</PercentItemFound></SuggestedCategory><SuggestedCategory><Category><CategoryID>123417</CategoryID><CategoryName>Caricabatterie e dock</CategoryName><CategoryParentID>15032</CategoryParentID><CategoryParentID>9394</CategoryParentID><CategoryParentName>Telefonia fissa e mobile</CategoryParentName><CategoryParentName>Accessori cellulari e palmari</CategoryParentName></Category><PercentItemFound>0</PercentItemFound></SuggestedCategory></SuggestedCategoryArray><CategoryCount>10</CategoryCount></GetSuggestedCategoriesResponse>

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




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")


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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...