Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Oracle DB升级后XPath.evaluate()的错误行为_Java_Xml_Oracle_Dom_Xpath - Fatal编程技术网

Java Oracle DB升级后XPath.evaluate()的错误行为

Java Oracle DB升级后XPath.evaluate()的错误行为,java,xml,oracle,dom,xpath,Java,Xml,Oracle,Dom,Xpath,我们最近将数据库从Oracle 11gR1升级到11gR2。之后,javax.xml.xpath.xpath.evaluate()不会给出预期的输出- // SAVING YOU FROM ALL UNWANTED CODE - I've queried for data and returned to ResultSet object java.sql.Blob blobObj = rs.getBlob("DOCBODY"); InputStream inpStr = new java.io

我们最近将数据库从
Oracle 11gR1
升级到
11gR2
。之后,
javax.xml.xpath.xpath.evaluate()
不会给出预期的输出-

// SAVING YOU FROM ALL UNWANTED CODE - I've queried for data and returned to ResultSet object
java.sql.Blob blobObj = rs.getBlob("DOCBODY");

InputStream inpStr = new java.io.ByteArrayInputStream(blobObj.getBytes(1L, 
(int) blobObj.length()));

javax.xml.parsers.DocumentBuilderFactory domFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();

domFactory.setNamespaceAware(true);

javax.xml.parsers.DocumentBuilder builder = domFactory.newDocumentBuilder();

org.w3c.dom.Document doc = builder.parse(new org.xml.sax.InputSource(inpStr));

doc.getDocumentElement().normalize();

org.w3c.dom.Node infoTag = (org.w3c.dom.Node) xPath.evaluate("sc:configuration/sc:info", doc,
javax.xml.xpath.XPathConstants.NODE); // configuration is one of the <parent_tags> and 
info is <configuration> tag's <child_tag>

我非常想知道是什么导致了这种行为。

您能提供在更改之前生成的、现在正在生成的输出吗?
domFactory.setNamespaceAware(true)-删除此行或在xpath对象中添加对命名空间的支持。您关于“代码没有问题,因为它以前工作过”的推断似乎有缺陷。您的代码可能依赖于Oracle已修复的错误。您尚未向我们展示xPath对象的初始化。特别是,您确定正确绑定了名称空间前缀“sc”吗?我已经添加了代码段。您能否提供在更改之前生成的、现在正在生成的输出
javax.xml.xpath.xpath.evaluate()
(或至少指定具体不同的内容)
domFactory.setNamespaceAware(true)-删除此行或在xpath对象中添加对命名空间的支持。您关于“代码没有问题,因为它以前工作过”的推断似乎有缺陷。您的代码可能依赖于Oracle已修复的错误。您尚未向我们展示xPath对象的初始化。特别是,您确定正确绑定了名称空间前缀“sc”吗?我已经添加了代码段。
javax.xml.xpath.XPath xPath = javax.xml.xpath.XPathFactory.newInstance().newXPath();
xPath.setNamespaceContext(new MyNamespaceContext()); //MyNamespaceContext is just an inner class that extends javax.xml.namespace.NamespaceContext

// Retrieving information available in the XML file
org.w3c.dom.Node infoTag = (org.w3c.dom.Node) xPath.evaluate("sc:configuration/sc:info", doc, javax.xml.xpath.XPathConstants.NODE);
if (null != infoTag) {
     org.w3c.dom.NodeList docNodeList = (org.w3c.dom.NodeList) xPath.evaluate("sc:documents/sc:document", infoTag, javax.xml.xpath.XPathConstants.NODESET); //documents is a child tag of info tag and document is a child tag of documents tag
     if (null != docNodeList) {
           ...
           ...
           for (int i = 0; i < docNodeList.getLength(); i++) {
/* We are supposed to enter this condition, but since something is wrong with "doc" object
 because docNodeList.getLength() is returning 0, we are not able to do so after the Oracle 
DB upgrade. Before we upgraded to 11.2.0.4, this part of code was working as expected.
 However, it still works as expected when I go with doc.getElementsByTagName().*/
           }
           ...
           ...
     }
     ...
     ...
}

private static class MyNamespaceContext implements NamespaceContext {

        public String getNamespaceURI(final String prefix) {
            if ("sc".equals(prefix)) {
                return "http://www.dummyurl.com/configuration";
            }
            return null;
        }

        public String getPrefix(final String namespaceURI) {
            return null;
        }

        public Iterator getPrefixes(final String namespaceURI) {
            return null;
        }
    }