Jump to content

_XMLGetPath need help?


Recommended Posts

Hi all, Please help me with this code, i'm trying to use _XMLGetPath

#include <_XMLDomWrapper.au3>
#include <Array.au3>

$oOXml = _XMLFileOpen("C:\direct.xml")

$retval = _XMLGetPath('//feed/entry')
_ArrayDisplay($retval)

Error Retrieving: //feed/entry

No matching node(s)found!

Here is xml file:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/noitems.css"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;DUcCRHs7fSp7ImA9WxBTGEk.&quot;">

<id>tag:blogger.com,1999:blog-</id>
<updated>2009-12-15T05:17:45.505+02:00</updated>
<title>SPEED</title>
<subtitle type="html" />
<link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://baltagy.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http:///" />
<link rel="hub" href="http://pubsubhubbub.appspot.com/" />
<link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/" />


<author>
<name></name>
<uri>http://www.blogger.com/profile/0319992</uri>
<email></email>
</author>

<generator version="7.00" uri="http://www.blogger.com">Blogger</generator>

<openSearch:totalResults>790</openSearch:totalResults
><openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>25</openSearch:itemsPerPage>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="" />

<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" />

<entry gd:etag="W/&quot;DUcHQHk8fyp7ImA9WxBTGEk.&quot;">
<id>tag:blogger.com,1999:blog-3959659278969612831.post-611731628003799747</id>
<published>2009-12-15T05:15:00.002+02:00</published>
<updated>2009-12-15T05:17:11.777+02:00</updated>
<app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-15T05:17:11.777+02:00</app:edited>
<category scheme="http://www.blogger.com/atom/ns#" term="Graphics" />
<title>Photodex ProShow Producer v4.1.2712</title>
<content type="html"></content>

<author>
<name></name>
<uri>http://www.blogger.com/profile</uri>
<email></email>
<gd:extendedProperty name="OpenSocialUserId" value="02157891" />
</author>
<feedburner:origLink>http://</feedburner:origLink>
</entry></feed>
Link to comment
Share on other sites

With the XML simplified like this:

<?xml version="1.0" encoding="UTF-8"?>
<feed>
    <id>tag:blogger.com,1999:blog-</id>
    <updated>2009-12-15T05:17:45.505+02:00</updated>
    <title>SPEED</title>
    <subtitle type="html" />
    <link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://baltagy.blogspot.com/feeds/posts/default" />
    <link rel="alternate" type="text/html" href="http:///" />
    <link rel="hub" href="http://pubsubhubbub.appspot.com/" />
    <link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/" />

    <author>
        <name></name>
        <uri>http://www.blogger.com/profile/0319992</uri>
        <email></email>
    </author>

    <generator version="7.00" uri="http://www.blogger.com">Blogger</generator>

    <openSearch>790</openSearch>
    <openSearch>1</openSearch>
    <openSearch>25</openSearch>
    <atom10 rel="self" type="application/atom+xml" href="" />

    <atom10 rel="hub" href="http://pubsubhubbub.appspot.com" />

    <entry gd="W/&quot;DUcHQHk8fyp7ImA9WxBTGEk.&quot;">
        <id>tag:blogger.com,1999:blog-3959659278969612831.post-611731628003799747</id>
        <published>2009-12-15T05:15:00.002+02:00</published>
        <updated>2009-12-15T05:17:11.777+02:00</updated>
        <app >2009-12-15T05:17:11.777+02:00</app>
        <category scheme="http://www.blogger.com/atom/ns#" term="Graphics" />
        <title>Photodex ProShow Producer v4.1.2712</title>
        <content type="html"></content>

        <author>
            <name></name>
            <uri>http://www.blogger.com/profile</uri>
            <email></email>
            <gd name="OpenSocialUserId" value="02157891" />
        </author>
        <feedburner>http://</feedburner>
    </entry>
</feed>

This works:

#include <_XMLDomWrapper.au3>
#include <Array.au3>

$debugging = True
$iRET = _XMLFileOpen(@ScriptDir & "\Test1.xml")
ConsoleWrite("$iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)
$retval = _XMLGetPath('//feed/entry')
ConsoleWrite("$retval = " & $retval & "; @error = " & @error & "; @extended = " & @extended & @LF)
If IsArray($retval) Then _ArrayDisplay($retval)

I guess you could start from there and then plug the namespace stuff back in until you figure out which one is confusing it.

:D

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

It doesn't work for my xml file, cause in your xml file you use <feed> but in my original file is

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;DUcCRHs7fSp7ImA9WxBTGEk.&quot;">

How can i fix it?

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

I've the same problem with google calendar and after 20 days of research, i've recently found THE solution. This solution work with google calendar and google feeder.

The librairie "_XMLDOMWrapper" use version 6 of Msxml2 ("Msxml2.DOMdocument.6.0"), but version 4,5 and 6 of MsXml are compliant with W3C. Version 1, 2 and 3 are compliant with....microsoft Xml specifications only ;-) and don't need namespaces.

So for version compliant with W3C you MUST declare and use NAMESPACES. Your code work if you write :

$debugging = True
$iRET = _XMLFileOpen(@ScriptDir & "\fichier.xml",'xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"')
ConsoleWrite("$iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)
$retval = _XMLGetPath('//atom:feed/atom:entry')
ConsoleWrite("$retval = " & $retval & "; @error = " & @error & "; @extended = " & @extended & @LF)
If IsArray($retval) Then _ArrayDisplay($retval)

It's work with my version AutoIt3.3.4.0 of autoit, on my computer :See my console.

>Running:(3.3.4.0):C:\PF\AutoIt3\autoit3.exe "C:\Users\TOLA\Downloads\0Progs\0Autoit\0DATA\GCalendar\LireXml.au3"   
$iRET = 1; @error = 0; @extended = 0
GetPath list length:1
parent feed

parent #document

Path node> /feed/entry

$retval = ; @error = 0; @extended = 0

Be carefully, i've add 'xmlns:atom="http://www.w3.org/2005/Atom"......' for namespaces declaration and "$retval = _XMLGetPath('//atom:feed/atom:entry')" for xml tag prefix. I'm not sure for XPath, maybe someone can help us for make good XPath research !?!?

You must take the same namespaces found in the root tag, the "feed" tag in Google Data, but just take xmlns attributs.

Excuse my poor english :D .

Link to comment
Share on other sites

@FourLC: Thanks for the info! I didn't understand how it could work at first, because the "atom" namespace is not declared in the XML document. I finally figured out that the DEFAULT namespace was associated with the URI "http://www.w3.org/2005/Atom", so you could have named it anything when opening the file (here, I called it "dingleberry"):

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

$debugging = True

$iRET = _XMLFileOpen(@ScriptDir & "\Test1.xml", 'xmlns:dingleberry="http://www.w3.org/2005/Atom"')
ConsoleWrite("$iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)

$retval = _XMLGetPath('//dingleberry:feed/dingleberry:entry')
ConsoleWrite("$retval = " & $retval & "; @error = " & @error & "; @extended = " & @extended & @LF)

If IsArray($retval) Then _ArrayDisplay($retval)

This is not only true for the default namespace. The same cross reference happens with the others. In this example I opened it with an "applepie" namespace for "http://a9.com/-/spec/opensearch/1.1/":

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

$debugging = True

$iRET = _XMLFileOpen(@ScriptDir & "\Test1.xml", 'xmlns:dingleberry="http://www.w3.org/2005/Atom" xmlns:applepie="http://a9.com/-/spec/opensearch/1.1/"')
ConsoleWrite("$iRET = " & $iRET & "; @error = " & @error & "; @extended = " & @extended & @LF)

$retval = _XMLGetPath('//dingleberry:feed/applepie:totalResults')
ConsoleWrite("$retval = " & $retval & "; @error = " & @error & "; @extended = " & @extended & @LF)

If IsArray($retval) Then _ArrayDisplay($retval)

:D

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