Sign in to follow this  
Followers 0
grandnagus

Help with reading a XML file

5 posts in this topic

Hello,

I was able to figure out how to search a basic XML using the _XMLDomWrapper.au3 but I have a requirement to read from a XML with some processing instructions and comments.

Here is an example of a file I am able to read:

<SOFTPKG NAME = "{D5B5C661-8BB1-11d2-84AF-0000F63192AF}" VERSION = "1.0.0.0">

<TITLE>test</TITLE>

<DEPENDENCY>

<SOFTPKG>

<IMPLEMENTATION>

<CODEBASE HREF = "acrobat.cab" />

</IMPLEMENTATION>

</SOFTPKG>

</DEPENDENCY>

</SOFTPKG>

But if the file contains processing instructions and comments like this, then my scrip can not read.

<?xml version="1.0"?>

<!DOCTYPE SOFTPKG SYSTEM "http://www.microsoft.com/standards/osd/osd.dtd" >

<?XML::namespace href="http://www.microsoft.com/standards/osd/msicd.dtd" as="MSICD"?>

<SOFTPKG NAME = "{D5B5C661-8BB1-11d2-84AF-0000F63192AF}" VERSION = "2,0,0,0">

<TITLE>Acrobat Reader</TITLE>

<ABSTRACT>

Adobe Acrobat Reader

</ABSTRACT>

<IMPLEMENTATION>

<OS VALUE="WinNT"><OSVERSION VALUE="4,0,0,0"/></OS>

<OS VALUE="Win95"/>

<CODEBASE HREF = "Acrobat.cab" />

</IMPLEMENTATION>

</SOFTPKG>

How do I "ignore" this part of the xml file?

<?xml version="1.0"?>

<!DOCTYPE SOFTPKG SYSTEM "http://www.microsoft.com/standards/osd/osd.dtd" >

<?XML::namespace href="http://www.microsoft.com/standards/osd/msicd.dtd" as="MSICD"?>

Here is my code:

;start xml read test

#include <_XMLDomWrapper.au3>

Global $Title, $FileOpen

Func _GetFirstValue($node)
    $ret_val = _XMLGetValue($node)
    If IsArray($ret_val) Then
        Return ($ret_val[1])
    Else
        Return SetError(1,3,0)
    EndIf
EndFunc


$FileOpen = _XMLFileOpen("C:\Categories\Cabs\temp\test.osd")

;if $FileOpen = -1 Then
;MsgBox(48, "Open File Correctly?", "NO")
;else 
;MsgBox(0, "File ?", $FileOpen)
;EndIf


$node = "//TITLE"
$Title = _GetFirstValue($node)

$Version = _XMLGetAttrib('(/SOFTPKG)', 'VERSION')
$Dependency = _XMLGetAttrib('(//CODEBASE)', 'HREF')
;_XMLGetField('(//TITLE)')

if $Title = -1 Then
MsgBox(48, "Error", "Could Not Load values")
else
MsgBox(0, "Test Window", $Title & " " & $Version & " " & $Dependency)
EndIf


;end xml read test

Share this post


Link to post
Share on other sites



There's something wrong with the way you have the namespace declaration after the DOCTYPE. If that is commented out it loads fine:

#include <_XMLDOMWrapper.au3>

$debugging = True ; Global declared inside _XMLDOMWrapper.au3

Global $sXML = '<?xml version="1.0"?>' & @CRLF & _
'<!DOCTYPE SOFTPKG SYSTEM "http://www.microsoft.com/standards/osd/osd.dtd" >' & @CRLF & _
'<!--?XML::namespace href="http://www.microsoft.com/standards/osd/msicd.dtd" as="MSICD"?-->' & @CRLF & _
'<SOFTPKG NAME = "{D5B5C661-8BB1-11d2-84AF-0000F63192AF}" VERSION = "2,0,0,0">' & @CRLF & _
'   <TITLE>Acrobat Reader</TITLE>' & @CRLF & _
'   <ABSTRACT>' & @CRLF & _
'       Adobe Acrobat Reader' & @CRLF & _
'   </ABSTRACT>' & @CRLF & _
'   <IMPLEMENTATION>' & @CRLF & _
'       <OS VALUE="WinNT">' & @CRLF & _
'           <OSVERSION VALUE="4,0,0,0"/>' & @CRLF & _
'       </OS>' & @CRLF & _
'       <OS VALUE="Win95"/>' & @CRLF & _
'       <CODEBASE HREF="Acrobat.cab" />' & @CRLF & _
'   </IMPLEMENTATION>' & @CRLF & _
'</SOFTPKG>'

Global $iRET = _XMLLoadXML($sXML)
ConsoleWrite("Debug:  @error = " & @error & "; $iRET = " & $iRET & @LF)

:)


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

Share this post


Link to post
Share on other sites

There's something wrong with the way you have the namespace declaration after the DOCTYPE. If that is commented out it loads fine:

#include <_XMLDOMWrapper.au3>

$debugging = True ; Global declared inside _XMLDOMWrapper.au3

Global $sXML = '<?xml version="1.0"?>' & @CRLF & _
'<!DOCTYPE SOFTPKG SYSTEM "http://www.microsoft.com/standards/osd/osd.dtd" >' & @CRLF & _
'<!--?XML::namespace href="http://www.microsoft.com/standards/osd/msicd.dtd" as="MSICD"?-->' & @CRLF & _
'<SOFTPKG NAME = "{D5B5C661-8BB1-11d2-84AF-0000F63192AF}" VERSION = "2,0,0,0">' & @CRLF & _
'   <TITLE>Acrobat Reader</TITLE>' & @CRLF & _
'   <ABSTRACT>' & @CRLF & _
'       Adobe Acrobat Reader' & @CRLF & _
'   </ABSTRACT>' & @CRLF & _
'   <IMPLEMENTATION>' & @CRLF & _
'       <OS VALUE="WinNT">' & @CRLF & _
'           <OSVERSION VALUE="4,0,0,0"/>' & @CRLF & _
'       </OS>' & @CRLF & _
'       <OS VALUE="Win95"/>' & @CRLF & _
'       <CODEBASE HREF="Acrobat.cab" />' & @CRLF & _
'   </IMPLEMENTATION>' & @CRLF & _
'</SOFTPKG>'

Global $iRET = _XMLLoadXML($sXML)
ConsoleWrite("Debug:  @error = " & @error & "; $iRET = " & $iRET & @LF)

:)

I do not have an option to change these files. They are in my current environment.

Share this post


Link to post
Share on other sites

I didn't try that hard, but casual googling did not turn up a valid example of that "XML::NAMESPACE" definition. It doesn't match anything in the W3C description of namespaces either.

I'm not an XML expert, but if I had to work with that format without finding out any more about it, I would just delete or comment out that part by string manipulation before trying to load it.

Better would be to contact somebody familiar with the source application and find out what it was meant for.

:)


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

Share this post


Link to post
Share on other sites

I didn't try that hard, but casual googling did not turn up a valid example of that "XML::NAMESPACE" definition. It doesn't match anything in the W3C description of namespaces either.

I'm not an XML expert, but if I had to work with that format without finding out any more about it, I would just delete or comment out that part by string manipulation before trying to load it.

Better would be to contact somebody familiar with the source application and find out what it was meant for.

:)

The XML's are very old and used by a legacy application.

I will try to solve using your sugggestions. Thanks for the help.

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
Sign in to follow this  
Followers 0