public static String evaluate(XmlObject xmlbean, String path) {
        XmlCursor cursor = xmlbean.newCursor();
        String value;
        
// 1.2.3. use XQuery or selectPath
//
//        cursor.toFirstChild();
//        String defaultNamespace = cursor.namespaceForPrefix("");
//        String namespaceDecl = "declare default element namespace '" + defaultNamespace + "';";
//        Map<String,String> namespaces = new HashMap<String,String>();
//        cursor.getAllNamespaces(namespaces);
//        for (String prefix : namespaces.keySet())
//        {
//            namespaceDecl += "declare namespace " + prefix + "='" + namespaces.get(prefix) + "';";
//        }
//  1. use XQuery
//        XmlCursor results = cursor.execQuery(namespaceDecl + path);
//        value = (results==null)?null:results.getTextValue();
        
//  2. use selectPath on XmlObject
//        XmlObject[] result = xmlbean.selectPath(namespaceDecl + path);
        
//  3. use selectPath on XmlCursor   
//        cursor.toParent();
//        XmlOptions options = new XmlOptions();
//        options.put(Path.PATH_DELEGATE_INTERFACE,"org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath");
//        cursor.selectPath(namespaceDecl + path, options);
//        if (cursor.getSelectionCount()>0) {
//            cursor.toNextSelection();
//            value = cursor.getTextValue();
//        } else value = null;

// 4. use our own implementation
        try {
            XmlPath matcher = new XmlPath(path);
            value = matcher.evaluate_segment(cursor, matcher.path_seg);
        } catch (XmlException e) {
            value = null; // xpath syntax error - treated as no match
        }
        
        cursor.dispose();
        return value;
    }
public static String evaluate ( XmlObject xmlbean , String path ) { XmlCursor cursor = xmlbean . newCursor ( ) ; String value ; try { XmlPath matcher = new XmlPath ( path ) ; value = matcher . evaluate_segment ( cursor , matcher . path_seg ) ; } catch ( XmlException e ) { value = null ; } cursor . dispose ( ) ; return value ; }
Using XPath or XQuery.
NOTE!!!! To use this code, need to include
xbean_xpath.jar, saxon9.jar, saxon9-dom.jar in CLASSPATH
in startWebLogic.cmd
@param xmlbean
@param path
@return