xHarbour Reference Documentation > Class Reference (textmode) xHarbour Developers Network  

TXmlIteratorRegEx()

Creates a new TXmlIteratorRegEx object.

Syntax

TXmlIteratorRegEx():new( <oTXmlNode> ) --> oTXmlIteratorRegEx

Arguments

<oTXmlNode>
This is a TXmlNode() object to create the iterator object for. It serves as starting node for iterating.

Return

The function returns a TXmlIteratorRegEx object and method :new() initializes it.

Description

The TXmlIteratorRegEx class is derived from the TXmlIterator() class and has the same methods. The only difference is that regular expressions are used to define search criteria for finding a particular XML node in an XML tree. The regular expressions are defined once with the :find() method, which searches for the first matching XML node. Subsequent XML nodes matching the regular expressions then searched with the :next() method.

The end of a search is indicated when either :find() or :next() return NIL instead of a TXmlNode object matching the regular expressions.

Search methods

:find( ... ) --> oTXmlNode | NIL
Searches the first XML node matching the regular expressions.
:next() --> oTXmlNode | NIL
Searches the next XML node matching the regular expressions.

Info

See also:TXmlDocument(), TXmlNode(), TXmlIterator(), TXmlIteratorScan()
Category: Object functions , xHarbour extensions
Source:rtl\txml.prg
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example use the Customer.xml file as created with the
// TXmlDocument() example. Two XmlIteratorScan objects are used
// to scan the <record> nodes and field nodes below record nodes.
// The example displays the contents of the <lastname> nodes
// whose textual content begin with "R" or "S".

   PROCEDURE Main
      LOCAL oXmlDoc := TXmlDocument():new()
      LOCAL oXmlRecord, oXmlField, oXmlRecScan, oXmlFieldScan
      LOCAL cRegEx := "ˆ[R?]|ˆ[S?]"

      oXMlDoc:read( Memoread( "customer.xml" ) )

      oXmlNode := oXmlDoc:findFirst( "records" )

      // iterator for <record> nodes
      oXmlRecScan := TXmlIteratorScan():new( oXmlNode )
      oXmlRecord  := oXmlRecScan:find( "record" )

      DO WHILE oXmlRecord <> NIL
         // iterator for <fieldname> nodes
         oXmlFieldScan := TXmlIteratorRegEx():new( oXmlRecord )
         oXmlField     := oXmlFieldScan:find( "lastname" ,,, cRegEx )

         IF oXmlField <> NIL
            ? oXmlField:cData
         ENDIF

         oXmlRecord := oXmlRecScan:next()
      ENDDO

   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe