Parsing an XML Document with XPath
Subject:   parsing Weblogic10 domain config file is not working
Date:   2008-05-13 11:52:41
From:   faizy

My application deploys in weblogic 10 using an install script. Before deploying the application I validate the domainís config.xml file by parsing it using the XPath expressions. However, the parsing is not working as expected. After trial and error I noticed that in config.xml file if the xmlns attribute of the domain element is pointing to any value (such as xmlns="" or even a space xmlns=" ") then the parsing fails. When I change the attribute to empty value (xmlns="") then parsing works fine. I am not sure why it is failing. Since xmlns attribute is weblogic default and is not in my control to remove or ignore I am not sure how to work around it. I am bound to use DOM parsing instead of XPath even though I really wanted to use XPath expressions to keep the overhead of validation to minimum. Any help in this regard will be greatly appreciated.

I also wanted to know why I have to create new inputSource instance for every xPath.evaluate call. If I donít I get Read error - at Method) Ö

Thanks in advance for your help.

The config.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<domain xsi:schemaLocation="" xmlns="" xmlns:sec="" xmlns:wls="" xmlns:xsi="">
<security-configuration xmlns:xacml="">
<sec:authentication-provider xsi:type="wls:default-authenticatorType"/>
<sec:authentication-provider xsi:type="wls:default-identity-asserterType">
<sec:role-mapper xsi:type="xacml:xacml-role-mapperType"/>
<sec:authorizer xsi:type="xacml:xacml-authorizerType"/>
<sec:adjudicator xsi:type="wls:default-adjudicatorType"/>
<sec:credential-mapper xsi:type="wls:default-credential-mapperType"/>
<sec:cert-path-provider xsi:type="wls:web-logic-cert-path-providerType"/>

My XPath parser test class:
package com.test;

import org.xml.sax.InputSource;
import org.w3c.dom.*;
import javax.xml.xpath.*;

public class XPathTest {

private static final String fileName = "C:\\config.xml";
private XPathFactory factory = null;
private XPath xPath = null;
private InputSource inputSource = null;

public static void main(String argv[]) {
XPathTest t = new XPathTest();
try {
} catch (Exception e) {

public XPathTest() {
factory = XPathFactory.newInstance();
xPath = factory.newXPath();

private void test() throws Exception {
System.out.println("START > > > > > >");
inputSource = new InputSource(new FileInputStream(new File(this.fileName)));
System.out.println("Version: " + xPath.evaluate("/domain/domain-version", inputSource) );

inputSource = new InputSource(new FileInputStream(new File(this.fileName)));
String expression="/domain/server/name";
NodeList nodeList = (NodeList) xPath.evaluate(expression, inputSource, XPathConstants.NODESET);
for (int i=0;i Node n = nodeList.item(i);
System.out.println("Node Name: " + n.getNodeName());
System.out.println("Node Value: " + n.getChildNodes().item(0).getNodeValue());

System.out.println("END < < < < < <");