Jump to content
Sign in to follow this  
DCCD

I need help - StringRegExp

Recommended Posts

DCCD

Hi, i need help here's a xml file i need to check some data in the xml file but the second StringRegExp return 0 why?

Here's the XML file

<entry xmlns="http://www.w3.org/2005/Atom">
   <id>885454</id>
   <published>2013-11-10T21:53:00.001+02:00</published>
   <updated>2015-01-11T05:13:52.877+02:00</updated>
   <category scheme="kind" term="post" />
   <title type="text">TITLE</title>
   <content type="html" />
   <link rel="replies" type="application/atom+xml" href="/comments/default" title="Post Comments" />
   <link rel="replies" type="text/html" href="/comment-form" title="0 Comments" />
   <link rel="edit" type="application/atom+xml" href="/" />
   <link rel="self" type="application/atom+xml" href="/" />
   <link rel="alternate" type="text/html" href="/" title="TITLE" />
   <thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total>
</entry>

Autoit Script

$XML = FileRead(@ScriptDir & '\default.xml')

Local $nOffset = 1

Local $aArray
While 1
    $aArray = StringRegExp($XML, '(?s)<entry[^>]*>.*?</entry>', 1, $nOffset)

    If @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    For $i = 0 To UBound($aArray) - 1
        ;ConsoleWrite($aArray[$i])
        ConsoleWrite(StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 1, $nOffset)); return 0!
    Next
WEnd

Any help would be greatly appreciated

.

Share this post


Link to post
Share on other sites
jguinch

The last StringRegExp should return an array, not a string.

You should use ConsoleWrite(StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 1, $nOffset)[0]) instead, but in your case, $nOffset is out of range.

I don't really understand why you want to use $nOffset for, but maybe this code would match with your need :

Local $XML = FileRead(@ScriptDir & '\default.xml')

Local $aArray = StringRegExp($XML, '(?s)<entry[^>]*>.*?</entry>', 3)

If NOT @error Then
    For $i = 0 To UBound($aArray) - 1
        $aPublisher = StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 1)
        ConsoleWrite ( $aPublisher[0] )
    Next
EndIf
Edited by jguinch
  • Like 1

Share this post


Link to post
Share on other sites
SmOke_N

From your example, it's going to fail for us, you only provided 1 entry.  The return is the number of characters, then you ask it to search from that return on.  Anyway....  The first regex works for me when I double your xml example.

The ConsoleWrite(StringRegExp()) ... You know that it returns an array right?  Offset doesn't apply to that for/loop because you're accessing the data directly from the array.

So this should work if you're validating only:

ConsoleWrite(StringRegExp($aArray[$i], '(?i)<published>(.*?)</published>', 0) & @CRLF)
Edited by SmOke_N
Iterated validation
  • Like 1

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
SmOke_N

Out of curiosity, do the xml udf's from the forum not meet your needs?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
SmOke_N
  • Like 1

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×