< Day Day Up > |
Related Technologies: XPATH and XSLTThere 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 QueryLOCAL 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 > |