Related Technologies: XPATH and XSLT

 <  Day Day Up  >  

Related Technologies: XPATH and XSLT

There are other ancillary technologies that can be very valuable allies . One is XPATH, and the other is XSLT. Although they are not part of FoxPro or of Visual Basic .NET, they are very useful in building Web pages, a topic that we'll touch on later in this book. So we'll just take a quick look here.

XPATH is a language to manipulate XML. Using its abbreviated syntax, you can loop through an XML document, build a heading based on one type of node, list the child elements of that node in tabular form, and then repeat the pattern for each parent node. And you can do all this in a very cryptic syntax. That means there isn't much code to write, but it's hard.

XPATH expresses the contents of an XML document based on a model containing seven nodes: Root, Element, Attribute, NameSpace, Processing Instruction, Comments, and Text. The content of a document is referred to in terms of some node. Relative references such as parent, child, descendent , and others can also be used to identify a particular element within the document. There are XPATH functions as well. Using XPATH queries, you can do a lot with just a little code.

The example shown in Listing 7.31 reads an XML file, locates a section of text, and produces a list of the related elements using an embedded XPATH query. aaa and bbb are elements in the namespace of the XML that is to be read:

Listing 7.31. Visual Basic .NET Code to Read XML and List Part of Its Contents Using an Embedded XPATH Query
 LOCAL loDOM         AS "MSXML2.DOMDocument.4.0" LOCAL loNodeList    AS "MSXML2.IXMLDOMNodeList" loDOM = CREATEOBJECT ( "MSXML2.DOMDocument.4.0") loDOM.Load ( "CLIENTES.XML") loDOM.SetProperty ( "SelectNameSpaces", "xmlns:y="urn:vfp:mins" ) loNodeList = loDOM.SelectNodes ( "child::y:aaa/child::y:bbb" ) FOR EACH loNode IN loNodeList     ? loNode.XML ENDFOR 

The two lines of code set off in the middle of Listing 7.31 define the selection criteria for the nodes to be included. It's a very compact way to do something that otherwise would have to be required code. He who codes least codes best.

 <  Day Day Up  >  


Visual Fox Pro to Visual Basic.NET
Visual FoxPro to Visual Basic .NET
ISBN: 0672326493
EAN: 2147483647
Year: 2004
Pages: 130
Authors: Les Pinter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net