Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xalan namespace problem

Thread Tools

xalan namespace problem

lancelot_234 lancelot_234 is offline
Junior Member
Join Date: May 2010
Posts: 1

I'm trying to parse a xml file (that has namespace) using Xalan library.

I'm using the following files/code (from the example about namespace context in: :

- foo.xml


(unfortunately, I can't put foo.xml or in this post)

this is the code I'm using to parse the xml file:


import org.w3c.dom.*;
import org.xml.sax.SAXException;
import javax.xml.parsers.*;
import javax.xml.xpath.*;

public class XpathExampleFoo {

	  public static void main(String[] args) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException {
		  XpathExampleFoo a = new XpathExampleFoo();
	 } // end main
	public void analyzeXml() throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
	    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
	    domFactory.setNamespaceAware(true); // never forget this!
	    DocumentBuilder builder = domFactory.newDocumentBuilder();
	    Document doc = builder.parse("foo.xml");

	    XPathFactory factory = XPathFactory.newInstance();
	    XPath xpath = factory.newXPath();
	    xpath.setNamespaceContext(new MyNamespaceContext() );
	    XPathExpression expr 
	     = xpath.compile("/foo:document/bar:element");

	    Object result = expr.evaluate(doc, XPathConstants.NODESET);
	    NodeList nodes = (NodeList) result;
	    for (int i = 0; i < nodes.getLength(); i++) {
	} // end method
} // end class
when I execute "XpathExampleFoo", the result is: "null"

could somebody tell me what is wrong with the code?

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR CS0234: The type or namespace name 'DataAccessHelper' does not exist in the namespace 'BCC' (are you missing an assembly reference?) ASP .Net 0 01-06-2006 11:31 AM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
Upgrade of Xalan 1.2.2 and Xerces 1.4.4 to Xalan 2.6 and Xerces 2.6.2 cvissy XML 0 11-16-2004 07:06 AM
Namespace: Is it a scope or a namespace? Anonymous C++ 3 08-18-2003 01:31 PM
Help:Why can't I use namespace System.Web? It is said that this namespace doesn't exist. But it should exist. ASP .Net 1 07-29-2003 04:31 PM