Jump to content

XML problem


Recommended Posts

Can you help me out by showing how to read value (bold) into array.

partial XML example

<!-- Exported on: 2010-05-07 22:25:51 -->

<!-- Type: SkillData -->

<!-- Version: 0.4a -->

<Data Version="0.4a" CitizenshipID="F714-874F">

<PersonalData>

....

Using _XMLDOMWrapper.au3 UDF and managed to find out how to parse and read into array something like <Gender>Male</Gender> but CitizenshipID problem refuses to yield. Thank you in advance

Edited by shaqan
Link to comment
Share on other sites

#include <Array.au3>
$re = StringRegExp(ClipGet(), 'CitizenshipID="(.+)"', 3)
_ArrayDisplay($re)

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

As for using the _XMLDOMWrapper.au3 UDF to access this:

Your source XML is invalid, so it won't load. I corrected it to this for Test1.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Exported on: 2010-05-07 22:25:51 -->
<!-- Type: SkillData -->
<!-- Version: 0.4a -->
<PersonalData>
    <Data Version="0.4a" CitizenshipID="F714-874F"/>
</PersonalData>

Note the valid XML header, root element ("PersonalData"), and "/" closing the "Data" element, since it has no separate closing tag ("</Data>").

This script works correctly with the XML file above:

#include <_XMLDOMWrapper.au3>
#include <Array.au3>

Global $sXML_File = @ScriptDir & "\Test1.xml"
Global $iRET, $sRET

$iRET = _XMLFileOpen($sXML_File)
ConsoleWrite("Open:           $iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)
$sRET = _XMLGetAttrib("/PersonalData/Data", "Version")
ConsoleWrite("Version:        $sRET = " & $sRET & "; @error = " & @error & "; @extended = " & @extended & @LF)
$sRET = _XMLGetAttrib("/PersonalData/Data", "CitizenshipID")
ConsoleWrite("CitizenshipID:  $sRET = " & $sRET & "; @error = " & @error & "; @extended = " & @extended & @LF)

Output:

Open:           $iRET = 1; @error = 0; @extended = 0
Version:        $sRET = 0.4a; @error = 0; @extended = 0
CitizenshipID:  $sRET = F714-874F; @error = 0; @extended = 0

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...