BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
XALAN
org.apache.xml.serializer.Serializer Interface
org.apache.xml.serializer.Encodings Class
org.apache.xml.serializer.DOMSerializer Interface
org.apache.xml.dtm.DTMManager Class
org.apache.xalan.xslt.Process Class
org.apache.xalan.xslt.EnvironmentCheck Class
org.apache.xalan.xsltc.trax.TransformerFactoryImpl Class
org.apache.xalan.xsltc.trax.TemplatesImpl Class
org.apache.xalan.xsltc.trax.SmartTransformerFactoryImpl Class
org.apache.xalan.xsltc.trax.DOM2SAX Class
org.apache.xalan.transformer.XalanProperties Class
org.apache.xalan.transformer.TrAXFilter Class
org.apache.xalan.transformer.TransformerIdentityImpl Class
org.apache.xalan.processor.TransformerFactoryImpl Class
org.apache.xalan.lib.sql.XConnection Class
javax.xml.transform.sax.TemplatesHandler Class
XALAN Getting Started with XSLTC
The Usage of XALAN
Overview of XALAN - Java
<< WCF, WS, SOAP
XHTML >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :937

 

Xalan: The org.apache.xpath.CachedXPathAPI Class

Extends: java.lang.Object

Members

Signature

Public methods

XObject

eval(Node contextNode, java.lang.String str)

XObject

eval(Node contextNode, java.lang.String str, Node namespaceNode)

XObject

eval(Node contextNode, java.lang.String str, PrefixResolver prefixResolver)

XPathContext

getXPathContext()

NodeIterator

selectNodeIterator(Node contextNode, java.lang.String str)

NodeIterator

selectNodeIterator(Node contextNode, java.lang.String str, Node namespaceNode)

NodeList

selectNodeList(Node contextNode, java.lang.String str)

NodeList

selectNodeList(Node contextNode, java.lang.String str, Node namespaceNode)

Node

selectSingleNode(Node contextNode, java.lang.String str)

Node

selectSingleNode(Node contextNode, java.lang.String str, Node namespaceNode)

Overview

This is an alternative for the old XPathAPI class, which provided static methods for the purpose but had the drawback of instantiating a new XPathContext (and thus building a new DTMManager, and new DTMs) each time it was called. XPathAPIObject instead retains its context as long as the object persists, reusing the DTMs. This does have a downside: if you've changed your source document, you should obtain a new XPathAPIObject to continue searching it, since trying to use the old DTMs will probably yield bad results or malfunction outright... and the cached DTMs may consume memory until this object and its context are returned to the heap. Essentially, it's the caller's responsibility to decide when to discard the cache.

Method Overviews

The methods in this class are convenience methods into the low-level XPath API. These functions tend to be a little slow, since a number of objects must be created for each evaluation.

When performance is a issue, then better to use precompile the XPaths using the low-level API, and then just use the XPaths over and over.

Example of eval(Node contextNode, java.lang.String str)

eval() is used to used to get an instance of  XObject class. Using XObject instance, you can get result nodes in the form of iterator or NodeList

XObject xObject = cachedXPathAPI.eval(doc,"//person"); //Here XPath “//person” is applied on the context node doc.

NodeList nodes = xObject.nodelist();

     

      for(int i=0;i<nodes.getLength();i++)

      {

        Node node = nodes.item(i);

        NodeList childNodes = node.getChildNodes();

        for(int j=0;j<childNodes.getLength();j++)

        {

          if(childNodes.item(j).getNodeType()==Node.TEXT_NODE)

            System.out.println(childNodes.item(j).getNodeValue());

       

        }

      }

Example of selectSingleNode(Node contextNode, java.lang.String str)

selectSingleNode() is used to get a Node by applying XPath on the context node. If the given xpath returns more than one node, then only the first node will be returned.

Node node = cachedXPathAPI.selectSingleNode(doc,"//person"); //The xpath “//person” in applied on the context node

      NodeList childNodes = node.getChildNodes();

      for(int j=0;j<childNodes.getLength();j++)

      {

        if(childNodes.item(j).getNodeType()==Node.TEXT_NODE)

          System.out.println(childNodes.item(j).getNodeValue());

     

      }


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En
A Greate Opportunituy as a SQL Deve
An immediate job opportunity as a B

View all Jobs (Add yours)
View all CV (Add yours)



swimming pool contractor
chicago web site design
conference calls
Domain Names
conference call service
Donna karan sunglasses
answering service


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP