Jump to content

Recommended Posts

Posted (edited)

Sample read xml, export XML to LST formated. 

#include <Array.au3>

Global Const $oCOMError = ObjEvent("Autoit.Error", "_COMError")
Func _COMError()
  ConsoleWrite("! COM Error: " & $oCOMError.number & @LF)
EndFunc

$oXML = ObjCreate("MSXML2.DOMDocument")
;~ $oXML.loadXML(ClipGet())
$oXML.load(@ScriptDir & "\mame.xml")
$oXML.setProperty("SelectionLanguage", "XPath")
$total_ = $oXML.selectNodes("/mame/game").length

MsgBox(0,"Total de Jogos Encontrados",$total_)

ConsoleWrite("!-----------------------------------------------------------------------------------" & @LF & @LF)
For $oDirectoryRef In $oXML.selectNodes("/mame/game")

  $name_rom = $oDirectoryRef.getAttribute("name")
  $emulator_name = $oDirectoryRef.getAttribute("index")
  $check_bios = $oDirectoryRef.getAttribute("image")


  ConsoleWrite("> Game Rom: " & $name_rom &"  Index: "& $emulator_name &"  Image: "& $check_bios  & @LF)

For $Description_ In $oDirectoryRef.selectNodes("description")

    $description_val = $Description_.Text()
    ConsoleWrite("Descricao: " & $description_val & @LF)

For $year_ In $oDirectoryRef.selectNodes("year")

    $year_val = $year_.Text()
    ConsoleWrite("Ano: " & $year_val & @LF)

For $manufacturer_ In $oDirectoryRef.selectNodes("manufacturer")

    $manufacturer_val = $manufacturer_.Text()
    ConsoleWrite("Manufacturer: " & $manufacturer_val & @LF)

For $cloneof_ In $oDirectoryRef.selectNodes("cloneof")

    $cloneof_val = $cloneof_.Text()
    ConsoleWrite("Clone: " & $cloneof_val & @LF)

For $crc_ In $oDirectoryRef.selectNodes("crc")

    $crc_val = $crc_.Text()
    ConsoleWrite("CRC: " & $crc_val & @LF)

For $genre_ In $oDirectoryRef.selectNodes("genre")

    $genre_val = $manufacturer_.Text()
    ConsoleWrite("Estilo: " & $genre_val & @LF)
    Next
    Next
    Next
    Next
    Next
    Next
  ConsoleWrite(@LF)
  ConsoleWrite(@LF)
Next
ConsoleWrite("!-------------------------------------------------------" & @LF & @LF)
;SAMPLE XML READ

<game name="gjspace" sourcefile="namcos10.c">
        <description>Gekitoride-Jong Space (10011 Ver.A)</description>
        <year>2001</year>
        <manufacturer>Namco/Metro</manufacturer>
        <rom name="10011a_0.bin" size="16777216" crc="853e329e" sha1="dd272ab2de9052c5aeee9e0ead4ee3d14347593e" region="user2" offset="0"/>
        <rom name="10011a_1.bin" size="16777216" crc="7d4e96f7" sha1="41b0d27b93662f15547311c8723ac5141e129cab" region="user2" offset="1000000"/>
        <rom name="10011a_2.bin" size="16777216" crc="83111de6" sha1="d760fd41644104f6d3a2806ab4664df2c77bdc42" region="user2" offset="2000000"/>
        <rom name="10011a_3.bin" size="16777216" crc="b6ea8be7" sha1="3e65deda2b0e6758ce0ed05419ed096efb8ad755" region="user2" offset="3000000"/>
        <chip type="cpu" tag="maincpu" name="PSX CPU" clock="101491200"/>
        <display type="raster" rotate="0" width="640" height="480" refresh="60.000000" />
        <sound channels="0"/>
        <input players="2" buttons="6" coins="2" service="yes">
            <control type="joy8way"/>
        </input>
        <driver status="preliminary" emulation="preliminary" color="good" sound="preliminary" graphic="good" savestate="unsupported" palettesize="65536"/>
    </game>
    <game name="startrgn" sourcefile="namcos10.c">
        <description>Star Trigon (Japan, STT1 Ver.A)</description>
        <year>2002</year>
        <manufacturer>Namco</manufacturer>
        <rom name="stt1a_0.bin" size="16777216" crc="07513d66" sha1="baed445ff81e7f687e39b26648b3fe2ff601826b" region="user2" offset="0"/>
        <rom name="stt1a_1.bin" size="16777216" crc="f6e8e641" sha1="37c8c1482d652b46a744252721299448b15e1027" region="user2" offset="1000000"/>
        <chip type="cpu" tag="maincpu" name="PSX CPU" clock="101491200"/>
        <display type="raster" rotate="0" width="640" height="480" refresh="60.000000" />
        <sound channels="0"/>
        <input players="2" buttons="6" coins="2" service="yes">
            <control type="joy8way"/>
        </input>
        <driver status="preliminary" emulation="preliminary" color="good" sound="preliminary" graphic="good" savestate="unsupported" palettesize="65536"/>
    </game>
    <game name="gamshara" sourcefile="namcos10.c">
        <description>Gamshara (10021 Ver.A)</description>
        <year>2003</year>
        <manufacturer>Mitchell</manufacturer>
        <rom name="10021a.8e" size="16777216" crc="db0a3687" sha1="757360c43fba247e6c0c0fc66bb089575e19d646" region="user2" offset="0"/>
        <rom name="10021a.8d" size="16777216" crc="bebafef6" sha1="6c965c09f3186523d27c50894a15b9c1dd02a794" region="user2" offset="1000000"/>
        <chip type="cpu" tag="maincpu" name="PSX CPU" clock="101491200"/>
        <display type="raster" rotate="0" width="640" height="480" refresh="60.000000" />
        <sound channels="0"/>
        <input players="2" buttons="6" coins="2" service="yes">
            <control type="joy8way"/>
        </input>
        <driver status="preliminary" emulation="preliminary" color="good" sound="preliminary" graphic="good" savestate="unsupported" palettesize="65536"/>
    </game>
Edited by bhns

:bike: 

Att...Cleber Antônio Made in Bio zonte Minas Gerais  :sweating:

Posted (edited)

All those nested loops are ugly.

Since there is only one node you are trying to pull (within each parent), just use the following structure:

$sManufacturer = XML_GetTextNodeValue ( $oDirectoryRef.selectSingleNode("manufacturer"))

Func XML_GetTextNodeValue($oCallersNode)
    For $oChild In $oCallersNode.childNodes
        If Int($oChild.nodeType)==3 Then
            Return $oChild.nodeValue
        EndIf
    Next
EndFunc









Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted (edited)

Actually I realized that after adding more loop slowed to pass the 19,000 items.

Thanks 

jdelaney...

for the tip you use this function to make the call.

I had a problem in making call within another

sample  

 For $select_disk_chd In $oDirectoryRef.selectNodes("/mame/game/disk")
  $disk_chds = $oDirectoryRef.getAttribute("name") 
  ;MsgBox(0,"CHD >>"&$disk_chds)
 
 
 
Next
 
 
 
 
Func export_lst()


$disk_chds = 0
$total_disk = 0
$select_disk_chd = 0


$oXML = ObjCreate("MSXML2.DOMDocument")
;~ $oXML.loadXML(ClipGet())
$oXML.load(@ScriptDir & "\AIT-ARDLIST\ait-arcade.xml")
$oXML.setProperty("SelectionLanguage", "XPath")
$total_disk = $oXML.selectNodes("/mame/game/disk").length
$total_ = $oXML.selectNodes("/mame/game").length


;MsgBox(4096, "M.A.M.E All sets >>"& $total_)
;MsgBox(0,"M.A.M.E All sets >>","M.A.M.E All sets >>"&$total_disk)

ProgressOn("M.A.M.E List by Team AIT-ARCADE", "M.A.M.E All sets >>"&$total_, "0 percent")
Sleep(1000)

$in_bar = 0
;ConsoleWrite("!-----------------------------------------------------------------------------------" & @LF & @LF)
For $oDirectoryRef In $oXML.selectNodes("/mame/game")


    
     ;$disk_chds = $select_disk_chd.Text()
    
    ;MsgBox(4096, "M.A.M.E All sets >>"& $disk_chds)


  $name_rom = $oDirectoryRef.getAttribute("name")
  $emulator_name = $oDirectoryRef.getAttribute("sourcefile")
  $check_bios = $oDirectoryRef.getAttribute("isbios")
  ;$select_disk_chd = $oDirectoryRef.getAttribute("disk")
  ;$disk_chds = $select_disk_chd.Text("name")
  ;MsgBox(0,"CHD >>"&$disk_chds)
  ;For $select_disk_chd In $oDirectoryRef.selectNodes("disk")
  ;$disk_chds = $select_disk_chd.getAttribute("name")   
  ;MsgBox(0,"CHD >>"&$disk_chds)
 
 ; ConsoleWrite("> Game Rom: " & $name_rom &"  Emulador Name: "& $emulator_name &"  E uma Bios: "& $check_bios  & @LF)

For $Description_ In $oDirectoryRef.selectNodes("description")


    ;ProgressSet($Description_,$total_, $total_ & " games")

    $description_val = $Description_.Text()
    $game_edit = StringReplace($description_val, '(', '')
    $game_edit1 = StringReplace($game_edit, ')', '')
    $game_edit2 = StringReplace($game_edit1, '[', '')
    $game_edit3 = StringReplace($game_edit2, ']', '')
    $game_edit4 = StringReplace($game_edit3, '"', '')
    $game_edit5 = StringReplace($game_edit4, "'", "")
    $game_edit6 = StringReplace($game_edit5, "  ", " ")
    $description_val = $game_edit6
     $in_bar = $in_bar + 1
     $totallines = $total_
     $UpdatePercentDone = ( $in_bar /$totallines) * 100
    ProgressSet($UpdatePercentDone, $description_val, "M.A.M.E All sets:" & $in_bar & '/' & $totallines)

   ; ConsoleWrite("Descricao: " & $description_val & @LF)

For $year_ In $oDirectoryRef.selectNodes("year")

    $year_val = $year_.Text()
  ;  ConsoleWrite("Ano: " & $year_val & @LF)

For $manufacturer_ In $oDirectoryRef.selectNodes("manufacturer")

    $manufacturer_val = $manufacturer_.Text()
   ; ConsoleWrite("Manufacturer: " & $manufacturer_val & @LF)
   
        
  For $select_disk_chd In $oDirectoryRef.selectNodes("/mame/game/disk")
  $disk_chds = $oDirectoryRef.getAttribute("name") 
  ;MsgBox(0,"CHD >>"&$disk_chds)

    
    
    Next
    Next
    Next
    Next
    
read_options()  ; GRAVA LISTA
    Sleep(5) ; pra nao pesar o processador todo

  
 ; ConsoleWrite(@LF)
 ; ConsoleWrite(@LF)

Next
;ConsoleWrite("!-----------------------------------------------------------------------------------" & @LF & @LF)
ProgressSet(100, "Done", "Complete")
Sleep (3000)
ProgressOff()
;MsgBox(4096, "Lista Gerada com sucesso", "XML Export sucess "&@LF & $sFldr1&"ait-arcade.xml")

EndFunc

was slow but functional

 
Edited by bhns

:bike: 

Att...Cleber Antônio Made in Bio zonte Minas Gerais  :sweating:

Posted

       

jdelaney, thanky you

    Greatly improved his suggestion, but not understand a logic, they're selecting thedisk attribute name, but is bringing the return of the game name.

 

 

 

sample xml

<game name="jnero" sourcefile="vp101.c">
        <description>1</description>
        <year>2004</year>
        <manufacturer>ICE/Play Mechanix</manufacturer>
        <rom name="d710.05523.bin" size="1048576" crc="6054a066" sha1="58e68b7d86e6f24c79b99c8406e86e3c14387726" region="maincpu" offset="0"/>
        <rom name="8722a-1206.bin" size="524288" region="pic" status="nodump" offset="0"/>
        <disk name="jn010108" sha1="4f3e9c6349c9be59213df1236dba7d79e7cd704e" region="ide" index="0"/>
        <chip type="cpu" tag="maincpu" name="R5000 (little)" clock="300000000"/>
        <display type="raster" rotate="0" width="320" height="240" refresh="60.000000" />
        <sound channels="0"/>
        <input players="0">
        </input>
        <driver status="preliminary" emulation="preliminary" color="good" sound="preliminary" graphic="good" savestate="unsupported" palettesize="32768"/>
    </game>
<game name="jnero2" sourcefile="vp101.c">
        <description>2</description>
        <year>2004</year>
        <manufacturer>ICE/Play Mechanix</manufacturer>
        <rom name="d710.05523.bin" size="1048576" crc="6054a066" sha1="58e68b7d86e6f24c79b99c8406e86e3c14387726" region="maincpu" offset="0"/>
        <rom name="8722a-1206.bin" size="524288" region="pic" status="nodump" offset="0"/>
        <chip type="cpu" tag="maincpu" name="R5000 (little)" clock="300000000"/>
        <display type="raster" rotate="0" width="320" height="240" refresh="60.000000" />
        <sound channels="0"/>
        <input players="0">
        </input>
        <driver status="preliminary" emulation="preliminary" color="good" sound="preliminary" graphic="good" savestate="unsupported" palettesize="32768"/>
    </game>
Func export_lst()

    $oXML = ObjCreate("MSXML2.DOMDocument")
;~ $oXML.loadXML(ClipGet())
    $oXML.load(@ScriptDir & "\AIT-ARDLIST\ait-arcade.xml")
    $oXML.setProperty("SelectionLanguage", "XPath")
    $total_disk = $oXML.selectNodes("/mame/game/disk").length
    $total_ = $oXML.selectNodes("/mame/game").length


    ;MsgBox(4096, "M.A.M.E All sets >>"& $total_)
    ;MsgBox(0,"M.A.M.E All sets >>","M.A.M.E All sets >>"&$total_disk)

    ProgressOn("M.A.M.E List by Team AIT-ARCADE", "M.A.M.E All sets >>" & $total_, "0 percent")
    Sleep(1000)

    $in_bar = 0
    ;ConsoleWrite("!-----------------------------------------------------------------------------------" & @LF & @LF)
    For $oDirectoryRef In $oXML.selectNodes("/mame/game")
    
        $check_bios = "no"
        $disk_chds = "NODISK"
        $name_rom = $oDirectoryRef.getAttribute("name")
        $emulator_name = $oDirectoryRef.getAttribute("sourcefile")
        $check_bios = $oDirectoryRef.getAttribute("isbios")
        $description_val = XML_GetTextNodeValue($oDirectoryRef.selectSingleNode("description"))
        $manufacturer_val = XML_GetTextNodeValue($oDirectoryRef.selectSingleNode("manufacturer"))
        $year_val = XML_GetTextNodeValue($oDirectoryRef.selectSingleNode("year"))
        ; ConsoleWrite("> Game Rom: " & $name_rom &"  Emulador Name: "& $emulator_name &"  E uma Bios: "& $check_bios  & @LF)

        ;For $Description_ In $oDirectoryRef.selectNodes("description")
        ;$description_val = $Description_.Text()
        
        $game_edit = StringReplace($description_val, '(', '')
        $game_edit1 = StringReplace($game_edit, ')', '')
        $game_edit2 = StringReplace($game_edit1, '[', '')
        $game_edit3 = StringReplace($game_edit2, ']', '')
        $game_edit4 = StringReplace($game_edit3, '"', '')
        $game_edit5 = StringReplace($game_edit4, "'", "")
        $game_edit6 = StringReplace($game_edit5, "  ", " ")
        $description_val = $game_edit6
        $in_bar = $in_bar + 1
        $totallines = $total_
        $UpdatePercentDone = ($in_bar / $totallines) * 100
        ProgressSet($UpdatePercentDone, $description_val, "M.A.M.E All sets:" & $in_bar & '/' & $totallines)

        ; ConsoleWrite("Descricao: " & $description_val & @LF)


        ;For $year_ In $oDirectoryRef.selectNodes("year")

        ;$year_val = $year_.Text()
        
        
        ;  ConsoleWrite("Ano: " & $year_val & @LF)

        ;For $manufacturer_ In $oDirectoryRef.selectNodes("manufacturer")

        ;$manufacturer_val = $manufacturer_.Text()


        ; ConsoleWrite("Manufacturer: " & $manufacturer_val & @LF)


    
        For $select_disk_chd In $oDirectoryRef.selectNodes("disk")

            $disk_chds = $oDirectoryRef.getAttribute("name")
            ;MsgBox(0,"CHD >>"&$disk_chds)
            ;$disk_chds = XML_GetTextNodeValue2 ( $select_disk_chd.selectNodes("/mame/game/disk/name"))
            ;Next
            ;Next
        Next

        read_options() ; GRAVA LISTA

        Sleep(5) ; pra nao pesar o processador todo

        ; ConsoleWrite(@LF)
        ; ConsoleWrite(@LF)

    Next
    ;ConsoleWrite("!-----------------------------------------------------------------------------------" & @LF & @LF)
    ProgressSet(100, "Done", "Complete")
    Sleep(3000)
    ProgressOff()
    
EndFunc   ;==>export_lst



Func XML_GetTextNodeValue($oCallersNode)

    If Not IsObj($oCallersNode) Then
        ;Return SetError(1,0,-1)
        $oCallersNode = "NO_DATA_AA"
        Return $oCallersNode
    EndIf

    If $oCallersNode.childNodes < 1 Then
        $oCallersNode = "NO_DATA_AA"
        Return $oCallersNode
    Else

        For $oChild In $oCallersNode.childNodes
            If Int($oChild.nodeType) == 3 Then
                Return $oChild.nodeValue
            EndIf
        Next
    EndIf

EndFunc   ;==>XML_GetTextNodeValue

:bike: 

Att...Cleber Antônio Made in Bio zonte Minas Gerais  :sweating:

Posted

This will return the ANY disk element in the xml:

For $select_disk_chd In $oDirectoryRef.selectNodes("disk")

If you just want to return the disk element under the current directory, do this:

For $select_disk_chd In $oDirectoryRef.selectNodes("./disk")

Same is true of your other grabs...change them to:

$description_val = XML_GetTextNodeValue($oDirectoryRef.selectSingleNode("./description"))
        $manufacturer_val = XML_GetTextNodeValue($oDirectoryRef.selectSingleNode("./manufacturer"))
        $year_val = XML_GetTextNodeValue($oDirectoryRef.selectSingleNode("./year"))
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted

Continues  the problem, this selected the attribute name game, instead of disk name.

 

sample

 

<game name="jnero" sourcefile="vp101.c">
 <description>1</description>
<year>2004</year>
<manufacturer>ICE/Play Mechanix</manufacturer>
<disk name="jn010108" sha1="4f3e9c6349c9be59213df1236dba7d79e7cd704e" region="ide" index="0"/>
</game>

 

 

the select is correct, if there is not the disk field, and ignored when there puts the name of the rom.


I made a shortcut consuming, I made a script to read a field and another to readthe other, however I do not understand why.
 
 
 
For $oDirectoryRef In $oXML.selectNodes("/mame/game")

$check_bios = "no"
$name_rom = $oDirectoryRef.getAttribute("name")
$emulator_name = $oDirectoryRef.getAttribute("sourcefile")
$check_bios = $oDirectoryRef.getAttribute("isbios")
$description_val = XML_GetTextNodeValue($oDirectoryRef.selectSingleNode("description"))
$manufacturer_val = XML_GetTextNodeValue($oDirectoryRef.selectSingleNode("manufacturer"))
$year_val = XML_GetTextNodeValue($oDirectoryRef.selectSingleNode("year"))
; ConsoleWrite("> Game Rom: " & $name_rom &"  Emulador Name: "& $emulator_name &"  E uma Bios: "& $check_bios  & @LF)
;For $Description_ In $oDirectoryRef.selectNodes("description")
;$description_val = $Description_.Text()
$game_edit = StringReplace($description_val, '(', '')
$game_edit1 = StringReplace($game_edit, ')', '')
$game_edit2 = StringReplace($game_edit1, '[', '')
$game_edit3 = StringReplace($game_edit2, ']', '')
$game_edit4 = StringReplace($game_edit3, '"', '')
$game_edit5 = StringReplace($game_edit4, "'", "")
$game_edit6 = StringReplace($game_edit5, "  ", " ")
$description_val = $game_edit6
$in_bar = $in_bar + 1
$totallines = $total_
$UpdatePercentDone = ($in_bar / $totallines) * 100
ProgressSet($UpdatePercentDone, $description_val, "M.A.M.E All sets:" & $in_bar & '/' & $totallines)
; ConsoleWrite("Descricao: " & $description_val & @LF)
;For $year_ In $oDirectoryRef.selectNodes("year")
;$year_val = $year_.Text()
; ConsoleWrite("Ano: " & $year_val & @LF)
;For $manufacturer_ In $oDirectoryRef.selectNodes("manufacturer")
;$manufacturer_val = $manufacturer_.Text()
; ConsoleWrite("Manufacturer: " & $manufacturer_val & @LF)
For $select_disk_chd In $oDirectoryRef.selectNodes("./disk")
            $disk_chds = "NODISK"
$disk_chds = $oDirectoryRef.getAttribute("name")
;MsgBox(0,"CHD >>"&$disk_chds)
;$disk_chds = XML_GetTextNodeValue2 ( $select_disk_chd.selectNodes("/mame/game/disk/name"))
;Next
;Next
Next


read_options() ; GRAVA LISTA

Sleep(5) ; pra nao pesar o processador todo

; ConsoleWrite(@LF)
; ConsoleWrite(@LF)

Next
;ConsoleWrite("!-----------------------------------------------------------------------------------" & @LF & @LF)

:bike: 

Att...Cleber Antônio Made in Bio zonte Minas Gerais  :sweating:

Posted (edited)

Again, you don't need a loop to grab a single element, but you need to reference the proper element when you want to grab IT'S attributes:

Change from:

For $select_disk_chd In $oDirectoryRef.selectNodes("./disk")
            $disk_chds = "NODISK"
$disk_chds = $oDirectoryRef.getAttribute("name")
;MsgBox(0,"CHD >>"&$disk_chds)
;$disk_chds = XML_GetTextNodeValue2 ( $select_disk_chd.selectNodes("/mame/game/disk/name"))
;Next
;Next
Next

To:

For $select_disk_chd In $oDirectoryRef.selectNodes("./disk")
            $disk_chds = "NODISK"
$disk_chds = $select_disk_chd.getAttribute("name")
;MsgBox(0,"CHD >>"&$disk_chds)
;$disk_chds = XML_GetTextNodeValue2 ( $select_disk_chd.selectNodes("/mame/game/disk/name"))
;Next
;Next
Next

if you wanted to select teh attribute via an xpath, it would be:

//mame/game/disk/@name

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted

   Thank you, for your clarification, that God bless his intelligence, and being helpful.

For $select_disk_chd In $oDirectoryRef.selectNodes("./disk")  ;it confuse me, in reference
            
;$disk_chds = $oDirectoryRef.getAttribute("name")    

$disk_chds = $select_disk_chd.getAttribute("name")

Next

   Jdelaney muito obrigado mesmo, vivendo e apredendo rsrsrsrs  :thumbsup:  lets..go  :bike:

:bike: 

Att...Cleber Antônio Made in Bio zonte Minas Gerais  :sweating:

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