Jump to content

Recommended Posts

Posted

Show what you tried. This is not enough information. Are you familiar with XPath syntax? Is there a valid XML header above that in the file? Probably "options" is not the root node, so what is?

:)

Got it to work with:

_XMLGetValue("/options/opt1/opt[@name='a']/time")

and

_XMLUpdateField

  • 2 weeks later...
Posted

Hi all,

I am wondering if we can use the _XMLGetNodeCount() function to get the node count for a node based on a value.

For example, I have an XML file that lists different computers and their parameters. These computers were created for different purposes.

I am trying to get the number of computers that were created for "computation" purpose.

Here is a snippet of my XML document:

<item>

<id>1</id>

<Name>pc-instrumentcomp</Name>

<Dept2>IT</Dept2>

<lat>45.5747478365114</lat>

<lng>-73.7595677375793</lng>

<location>B104</location>

<floor>2</floor>

<purpose>computation</purpose>

</item>

Basically I would like to get the node count for all items that have purpose "computation".

$iProbClones = _XMLGetNodeCount("/item/purpose") will get me a count of all items in the XML file.

Can anyone help?

Thanks.

the123punch

Posted

Try:

_XMLGetNodeCount("/item[purpose=computation]")

Should get all "item" elements that contain a "purpose" element that is set to "computation".

;)

I tried what you are suggesting, but the function returns -1.

Did you test it?

the123punch

Posted

I tried what you are suggesting, but the function returns -1.

Did you test it?

the123punch

Nope. You didn't provide the text for a complete valid (but not too large) xml file to test against. For example, are the "item" elements really directly under the root?

;)

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
Posted

Nope. You didn't provide the text for a complete valid (but not too large) xml file to test against. For example, are the "item" elements really directly under the root?

;)

Please find attached a test sample of the XML file in question.

The <item> are not directly at the root level. But I tried the following:

$empCount = _XMLGetNodeCount("/list/item[itemtype=emp]")

which should return the count of all the items that have "emp" as itemtype but it returns -1.

Thanks.

the123punch

List.xml

Posted

What is "Pr꯯nom" in your file. Doesn't look like valid UTF-8.

;)

I'm sorry. The file I sent you is in French.

It works on my end but maybe not on yours.

I removed all the accented characters in this file so you can test it.

Thanks.

the123punch

List.xml

Posted

I'm sorry. The file I sent you is in French.

It works on my end but maybe not on yours.

I removed all the accented characters in this file so you can test it.

Thanks.

the123punch

Yeah, got over my stupid moment and figured that out right after posting the question. ;)

Anyway, the mistake was just "/" vice "\" and not putting single quotes around the search value because it was a string. So both of these work:

$iCnt = _XmlGetNodeCount("/list/item[floor=2]")
$iCnt = _XmlGetNodeCount("/list/item[itemtype='emp']")

:evil:

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
Posted

Yeah, got over my stupid moment and figured that out right after posting the question. ;)

Anyway, the mistake was just "/" vice "\" and not putting single quotes around the search value because it was a string. So both of these work:

$iCnt = _XmlGetNodeCount("/list/item[floor=2]")
$iCnt = _XmlGetNodeCount("/list/item[itemtype='emp']")

:evil:

Worked awesome!!

Many thanks.

the123punch

Posted

While I'm at it, I am wondering another thing.

On the same train of thought, if I wanted to select the value of the <location> tag from the 2nd <item> which has itemtype as "emp".. How do I do that?

I tried this:

$location= _XMLValue("/list/item[itemtype='emp'][" & $i & "]/location")

It returned an empty string...

I am baffled at how to do it cuz I tried so many things...

Thanks a lot.

the123punch

Posted (edited)

On the same train of thought, if I wanted to select the value of the <location> tag from the 2nd <item> which has itemtype as "emp".. How do I do that?

I tried this:

$location= _XMLValue("/list/item[itemtype='emp'][" & $i & "]/location")

It returned an empty string...

It's actually _XMLGetValue(), and it returns an array:
For $i = 1 To 3
    $aRET = _XMLGetValue("/list/item[itemtype='emp'][" & $i & "]/location")
    _ArrayDisplay($aRET, "$i = " & $i)
Next

:evil:

P.S. You can get the ones you want in an array in one pass, too (i.e. "[position()<4]" gets the first three). This demos the various XPaths we've used here:

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

$sXML = @ScriptDir & "\List.xml"
$iRET = _XMLFileOpen($sXML)
ConsoleWrite("Debug: $iRET = " & $iRET & @LF)
$iRET = _XmlGetNodeCount("/list/item[floor=2]")
ConsoleWrite("Debug: $iRET = " & $iRET & @LF)
$iRET = _XmlGetNodeCount("/list/item[itemtype='emp']")
ConsoleWrite("Debug: $iRET = " & $iRET & @LF)

; one at a time...
For $i = 1 To 3
    $aRET = _XMLGetValue("/list/item[itemtype='emp'][" & $i & "]/location")
    _ArrayDisplay($aRET, "$i = " & $i)
Next

; all three at once...
$aRET = _XMLGetValue("/list/item[itemtype='emp'][position()<4]/location")
_ArrayDisplay($aRET, "$aRET")

;)

Edited by PsaltyDS
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
Posted (edited)

Hi,

I'm looking a way for using multiple documents with the wrapper.

I saw a post in 2006 which tells about a hack in the wrapper to use an index on objdoc, but nothing is implemented in the up to date wrapper downloable in google.

Here is the post :

http://www.autoitscript.com/forum/index.php?showtopic=19848&st=40&p=155911&hl=xml%20wrapper%20multiple&fromsearch=1&#entry155911

It does not seems to be so hard to add the objdoc in every functions, so that multiple objdocs can be used at once, but it does not seems to be on the todolist.

You could do :

Global $objDoc

Func after($arg1,$arg2,$objarg=$objDoc)
consolewrite($objarg)
EndFunc

Func before($arg1,$arg2)
consolewrite($objDoc)
EndFunc

$objdoc=42
before(1,2)
after(1,2)

Can you confirm me that ?

Best regards,

Laurent.

Edited by lgr
Posted

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>

Posted

Hi all,

I'm hoping someone will be able to help as I am not familiar at all with writing XML parsing scripts.

Would I be able to extract the "Advertisement id" element from all entries where the attribute lastIsEnabled="false"?

The furtherest I seem to get is opening the file :evil:

Below is the topmost part of the xml file, I think what is tripping me up might be the Xpath syntax but I might be wrong.

<SWD key="nNj2dmBGXlFJHWQneGzyWw==">
    <Advertisements>
        <Advertisement id="{B2162A00-49DB-43FE-8F02-97B6F075D165}" name="WindowsXP-KB914388-x86-ENU.exe for MS06-036" version="6.0.6074.60" events="false" title="WindowsXP-KB914388-x86-ENU.exe for MS06-036" originator="NSInternal" package="{CD0F295B-3628-40A6-B4A6-11CF16F00E2D}" priority="Normal" available="2000-01-01 00:00:00" allowUserExecution="false" asap="false" runAtStartup="false" runAtLogon="false" retryAsap="true" notifyNewAdvert="0" notifyBeforeRun="0" notifyBeforeRunMaxDefer="0" immediateDownload="-2" minDownloadSpeed="-2" minRunSourceSpeed="-2" disableAfterRun="false" userOptional="false" recoverySnapshot="false" multicast="default">
            <Description><![CDATA[]]></Description>
            <Status removed="true" discovered="2008-01-31 19:58:30" notified="true" hasRunSuccessfully="false" userEnabled="false" lastIsEnabled="false"/>
        </Advertisement>

Would anyone be able to assist please?

;)

Posted

Hi all,

I'm hoping someone will be able to help as I am not familiar at all with writing XML parsing scripts.

Would I be able to extract the "Advertisement id" element from all entries where the attribute lastIsEnabled="false"?

The furtherest I seem to get is opening the file :evil:

Below is the topmost part of the xml file, I think what is tripping me up might be the Xpath syntax but I might be wrong.

<SWD key="nNj2dmBGXlFJHWQneGzyWw==">
    <Advertisements>
        <Advertisement id="{B2162A00-49DB-43FE-8F02-97B6F075D165}" name="WindowsXP-KB914388-x86-ENU.exe for MS06-036" version="6.0.6074.60" events="false" title="WindowsXP-KB914388-x86-ENU.exe for MS06-036" originator="NSInternal" package="{CD0F295B-3628-40A6-B4A6-11CF16F00E2D}" priority="Normal" available="2000-01-01 00:00:00" allowUserExecution="false" asap="false" runAtStartup="false" runAtLogon="false" retryAsap="true" notifyNewAdvert="0" notifyBeforeRun="0" notifyBeforeRunMaxDefer="0" immediateDownload="-2" minDownloadSpeed="-2" minRunSourceSpeed="-2" disableAfterRun="false" userOptional="false" recoverySnapshot="false" multicast="default">
            <Description><![CDATA[]]></Description>
            <Status removed="true" discovered="2008-01-31 19:58:30" notified="true" hasRunSuccessfully="false" userEnabled="false" lastIsEnabled="false"/>
        </Advertisement>

Would anyone be able to assist please?

;)

Santa sez you been nice:

#include <_XMLDOMWrapper.au3>

$sXML = @ScriptDir & "\Test1.xml"
_XMLFileOpen($sXML)
$RET = _XMLGetAttrib("/SWD/Advertisements/Advertisement[Status[@lastIsEnabled='false']]", "id")
ConsoleWrite("$RET = " & $RET & @LF)

Merry Christmas!

:evil:

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
  • 2 weeks later...
Posted

Hi, I'm interested in doing something simple. Your code is very complete but i must admit i don't know anything about this type of stuff. I'm trying to do the following. any help or direction would be awesome.

so i have the following directory tree

\Sales Reports\(This is the root directory for my application) And it contains the following

-Viewer.exe (this is a flash projector. It's an xml gallery)

-Update.exe (The autoit Script)

-catolog.xml(This is the xml file the viewer.exe uses)

-\Reports\ (This is a folder called "reports", in this folder are different folders and txt files that have the content for the gallery.

The user will download new reports and save

them to this folder. Each Report will have the following in the download. 1 txt file (this is the xml data for the report, this is

used by the flash gallery) and 1 folder of images and files. So when a user downloads a new report and runs the Update.exe

That's the Tree. This is how the Files should work.

Each download, or report has at least two parts, a txt file with the xml content and a folder containing all the files.There can be any number of these txt files in the reports directory. they all have different names. for example shoes.txt,cars.txt etc.

Here is an example of one of the txt files. This txt file is called Aug Shoe Report.txt

// Shoe Report aug 2010

// www.myreports.com

//101//

<ReportPages>

<page src="pages/img01.swf"></page>

<page src="pages/img01.swf"></page>

<page src="pages/img01.swf"></page>

<page src="pages/img01.swf"></page>

<page src="pages/img01.swf"></page>

<page src="pages/img01.swf"></page>

<page src="pages/img01.swf"></page>

<page src="pages/img01.swf"></page>

<page src="pages/img01.swf"></page>

<page src="pages/img01.swf"></page>

<page src="pages/img01.swf"></page>

<page src="pages/img01.swf"></page>

</ReportPages>

I would like the contents of the txt file copied and inserted into the catolog.xml file after //101//. (//101//, is just a tag i will put in the xml file so the autoit script knows where to insert the data.

So i hope this is making sense so far.

The update.exe will go through all the txt files in the root\reports\ Directory, extract all the data after the //101// tag and paste them one by one in the catolog.xml file after the //101// tag. All of this should be done with no input by the user. So essentially it's just a copy and paste thing.

Any help would be great, thanks. I'm doing all this because flash does not have the ability to write it's own xml files. or at least i don't know how to do this. Thanks again for your help.

Posted

This is not an XML topic, because that is not valid XML format. There is no XML header (i.e. '<?xml version="1.0"?>') and the first three lines are invalid comments, or something else non-XML.

You are looking at simple StringRegExp() or other string extraction of the data, not an XML reference.

$aResult = StringRegExp($sData, "(?://.+101//)(<page.+<//page>)", 3)

;)

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
Posted (edited)

Thanks, I'll check that out.

As for it being non XML your right i guess. The files i want to take data out of are incomplete XML files. the file i want to add them too is the rest of the xml file.

The idea here is when new reports are added to the directory my autoit.exe would add those parts to the xml file, effectively adding new content to the gallery. This would allow me to create a sort of drag and drop process.

So i guess i'm looking for a way to do this with txt files?

Happy New Year!!!!!!

Edited by Cyote101

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