faustf

xml formatted data help

6 posts in this topic

hi guys

 i have   a problem  with a  script  i have  this  array

Row|Col 0|Col 1
[0]|<CategoryID>|9355
[1]|<CategoryName>|Cellulari e smartphone
[2]|<CategoryParentID>|15032
[3]|<CategoryParentName>|Telefonia fissa e mobile
[4]|<PercentItemFound>|98
[5]|<CategoryID>|20349
[6]|<CategoryName>|Cover e custodie
[7]|<CategoryParentID>|15032
[8]|<CategoryParentID>|9394
[9]|<CategoryParentName>|Telefonia fissa e mobile
[10]|<CategoryParentName>|Accessori cellulari e palmari
[11]|<PercentItemFound>|1
[12]|<CategoryID>|43304
[13]|<CategoryName>|Cellulari: componenti
[14]|<CategoryParentID>|15032
[15]|<CategoryParentName>|Telefonia fissa e mobile
[16]|<PercentItemFound>|1
[17]|<CategoryID>|123422
[18]|<CategoryName>|Cavi e adattatori
[19]|<CategoryParentID>|15032
[20]|<CategoryParentID>|9394
[21]|<CategoryParentName>|Telefonia fissa e mobile
[22]|<CategoryParentName>|Accessori cellulari e palmari
[23]|<PercentItemFound>|0
[24]|<CategoryID>|123417
[25]|<CategoryName>|Caricabatterie e dock
[26]|<CategoryParentID>|15032
[27]|<CategoryParentID>|9394
[28]|<CategoryParentName>|Telefonia fissa e mobile
[29]|<CategoryParentName>|Accessori cellulari e palmari
[30]|<PercentItemFound>|0
[31]|<CategoryID>|58540
[32]|<CategoryName>|Proteggi schermo
[33]|<CategoryParentID>|15032
[34]|<CategoryParentID>|9394
[35]|<CategoryParentName>|Telefonia fissa e mobile
[36]|<CategoryParentName>|Accessori cellulari e palmari
[37]|<PercentItemFound>|0
[38]|<CategoryID>|80077
[39]|<CategoryName>|Cuffie
[40]|<CategoryParentID>|15032
[41]|<CategoryParentID>|9394
[42]|<CategoryParentName>|Telefonia fissa e mobile
[43]|<CategoryParentName>|Accessori cellulari e palmari
[44]|<PercentItemFound>|0
[45]|<CategoryID>|112190
[46]|<CategoryName>|Varese
[47]|<CategoryParentID>|1
[48]|<CategoryParentID>|914
[49]|<CategoryParentID>|20245
[50]|<CategoryParentID>|112173
[51]|<CategoryParentName>|Collezionismo
[52]|<CategoryParentName>|Cartoline
[53]|<CategoryParentName>|Paesaggistiche italiane
[54]|<CategoryParentName>|Lombardia
[55]|<PercentItemFound>|0
[56]|<CategoryID>|98863
[57]|<CategoryName>|Altro orologi e gioielli
[58]|<CategoryParentID>|281
[59]|<CategoryParentName>|Orologi e gioielli
[60]|<PercentItemFound>|0
[61]|<CategoryID>|88468
[62]|<CategoryName>|Vivavoce per auto
[63]|<CategoryParentID>|15032
[64]|<CategoryParentID>|9394
[65]|<CategoryParentName>|Telefonia fissa e mobile
[66]|<CategoryParentName>|Accessori cellulari e palmari
[67]|<PercentItemFound>|0

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
    _ArrayDisplay($aXML_Dirty)
    ;If FileExists($sPath_tempEND) Then
    ;   FileDelete($sPath_tempEND)
    ;EndIf
    If FileExists($sPath_tempStart) Then
        FileDelete($sPath_tempStart)
    EndIf
    Do
        If $aXML_Dirty[$DoCont][0] = "<CategoryID>" Then
            $categoriID = $aXML_Dirty[$DoCont][1]
            _True_write_File($sPath_tempStart, $categoriID & "_")
            $mm = 0
            $zz = 0
            ;$ContArr += 1
        EndIf

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

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

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

            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
                Else
                    $cc = 1
                EndIf
            EndIf
            ;$ContArr += 1
            ;If $aXML_Dirty[$DoCont][0] = "<PercentItemFound>" Then
            ;   $mm = 0
            ;   $zz = 0
            ;   $DoCont -= $ccPID
            ;EndIf
            ;$ContArr += 1
        EndIf
        ;MsgBox(0, '', 'son qui 91')
        $DoCont += 1
    Until $DoCont = UBound($aXML_Dirty)

    _ArrayDisplay($aXML_Dirty)
EndFunc   ;==>_eBay_Category_XML_clean

Func _True_write_File($sFilePath, $sDataWrite)

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

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)
    Next
    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 *
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

Spoiler

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 API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer 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 * Best coding practices * 

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

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: 2017-06-04

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

http://it.tinypic.com/r/14xf21w/9

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
    Next
Next
Redim $res[$n][4]
_ArrayDisplay($res, "sorted by categoryID")

; reorder the array, sort by parent name

_ArraySort($res, 0, 0, 0, 3)
;_ArrayDisplay($res)
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]
Next
_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