Code example for XPath

Methods: evaluate, setNamespaceContext

0
     * @see IEditorPart 
     */ 
    @Override 
    public boolean isSaveAsAllowed() { 
        return true; 
    } 
 
    /** 
     * Create the various form pages. 
     */ 
    @Override 
    protected void createFormPages() { 
        try { 
            addPage(new MenuTreePage(this));
        } catch (PartInitException e) {
            AdtPlugin.log(e, "Error creating nested page"); //$NON-NLS-1$
        } 
         
     } 
 
    /* (non-java doc) 
     * Change the tab/title name to include the project name. 
     */ 
    @Override 
    protected void setInput(IEditorInput input) {
        super.setInput(input);
        if (input instanceof FileEditorInput) {
            FileEditorInput fileInput = (FileEditorInput) input;
            IFile file = fileInput.getFile();
            setPartName(String.format("%1$s", file.getName()));
        } 
    } 
     
    /** 
     * Processes the new XML Model, which XML root node is given. 
     *  
     * @param xml_doc The XML document, if available, or null if none exists. 
     */ 
    @Override 
    protected void xmlModelChanged(Document xml_doc) {
        // init the ui root on demand 
        initUiRootNode(false /*force*/); 
 
        mUiRootNode.setXmlDocument(xml_doc);
        if (xml_doc != null) {
            ElementDescriptor root_desc = mUiRootNode.getDescriptor();
            try { 
                XPath xpath = AndroidXPathFactory.newXPath();
                Node node = (Node) xpath.evaluate("/" + root_desc.getXmlName(),  //$NON-NLS-1$
                        xml_doc,
                        XPathConstants.NODE);
                if (node == null && root_desc.isMandatory()) {
                    // Create the root element if it doesn't exist yet (for empty new documents) 
                    node = mUiRootNode.createXmlNode();