⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xpath.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    private NodeTest parseNodeTest( int typeToken, Tokens xtokens, NamespaceContext context )        throws XPathException {        switch(typeToken) {        case XPath.Tokens.EXPRTOKEN_NAMETEST_ANY:            return new NodeTest(NodeTest.WILDCARD);                    case XPath.Tokens.EXPRTOKEN_NAMETEST_NAMESPACE:        case XPath.Tokens.EXPRTOKEN_NAMETEST_QNAME:            // consume QName token            String prefix = xtokens.nextTokenAsString();            String uri = null;            if (context != null && prefix != XMLSymbols.EMPTY_STRING) {                uri = context.getURI(prefix);            }            if (prefix != XMLSymbols.EMPTY_STRING && context != null && uri == null) {                throw new XPathException("c-general-xpath-ns");            }                if (typeToken==XPath.Tokens.EXPRTOKEN_NAMETEST_NAMESPACE)                return new NodeTest(prefix,uri);                String localpart = xtokens.nextTokenAsString();            String rawname = prefix != XMLSymbols.EMPTY_STRING            ? fSymbolTable.addSymbol(prefix+':'+localpart)            : localpart;                return new NodeTest(new QName(prefix, localpart, rawname, uri));                default:            // assertion error            throw new XPathException("c-general-xpath");                    }    }            //    // Classes    //    // location path information    /**     * A location path representation for an XPath expression.     *      * @xerces.internal     *     * @author Andy Clark, IBM     */    public static class LocationPath        implements Cloneable {        //        // Data        //        /** List of steps. */        public Step[] steps;        //        // Constructors        //        /** Creates a location path from a series of steps. */        public LocationPath(Step[] steps) {            this.steps = steps;        } // <init>(Step[])        /** Copy constructor. */        protected LocationPath(LocationPath path) {            steps = new Step[path.steps.length];            for (int i = 0; i < steps.length; i++) {                steps[i] = (Step)path.steps[i].clone();            }        } // <init>(LocationPath)        //        // Object methods        //        /** Returns a string representation of this object. */        public String toString() {            StringBuffer str = new StringBuffer();            for (int i = 0; i < steps.length; i++) {                if (i > 0	&& (steps[i-1].axis.type!=Axis.DESCENDANT                    && steps[i].axis.type!=Axis.DESCENDANT) ){                    str.append('/');                }                str.append(steps[i].toString());            }            // DEBUG: This code is just for debugging and should *not*            //        be left in because it will mess up hashcodes of            //        serialized versions of this object. -Ac            if (false) {                str.append('[');                String s = super.toString();                str.append(s.substring(s.indexOf('@')));                str.append(']');            }            return str.toString();        } // toString():String        /** Returns a clone of this object. */        public Object clone() {            return new LocationPath(this);        } // clone():Object    } // class locationPath    /**     * A location path step comprised of an axis and node test.     *      * @xerces.internal     *     * @author Andy Clark, IBM     */    public static class Step        implements Cloneable {        //        // Data        //        /** Axis. */        public Axis axis;        /** Node test. */        public NodeTest nodeTest;        //        // Constructors        //        /** Constructs a step from an axis and node test. */        public Step(Axis axis, NodeTest nodeTest) {            this.axis = axis;            this.nodeTest = nodeTest;        } // <init>(Axis,NodeTest)        /** Copy constructor. */        protected Step(Step step) {            axis = (Axis)step.axis.clone();            nodeTest = (NodeTest)step.nodeTest.clone();        } // <init>(Step)        //        // Object methods        //        /** Returns a string representation of this object. */        public String toString() {            if (axis.type == Axis.SELF) {                return ".";            }            if (axis.type == Axis.ATTRIBUTE) {                return "@" + nodeTest.toString();            }            if (axis.type == Axis.CHILD) {                return nodeTest.toString();            }            if (axis.type == Axis.DESCENDANT) {                return "//";            }            return "??? ("+axis.type+')';        } // toString():String        /** Returns a clone of this object. */        public Object clone() {            return new Step(this);        } // clone():Object    } // class Step    /**     * Axis.     *      * @xerces.internal     *     * @author Andy Clark, IBM     */    public static class Axis        implements Cloneable {        //        // Constants        //        /** Type: child. */        public static final short CHILD = 1;        /** Type: attribute. */        public static final short ATTRIBUTE = 2;        /** Type: self. */        public static final short SELF = 3;        /** Type: descendant. */        public static final short DESCENDANT = 4;        //        // Data        //        /** Axis type. */        public short type;        //        // Constructors        //        /** Constructs an axis with the specified type. */        public Axis(short type) {            this.type = type;        } // <init>(short)        /** Copy constructor. */        protected Axis(Axis axis) {            type = axis.type;        } // <init>(Axis)        //        // Object methods        //        /** Returns a string representation of this object. */        public String toString() {            switch (type) {                case CHILD: return "child";                case ATTRIBUTE: return "attribute";                case SELF: return "self";                case DESCENDANT: return "descendant";            }            return "???";        } // toString():String        /** Returns a clone of this object. */        public Object clone() {            return new Axis(this);        } // clone():Object    } // class Axis    /**     * Node test.     *      * @xerces.internal     *     * @author Andy Clark, IBM     */    public static class NodeTest        implements Cloneable {        //        // Constants        //        /** Type: qualified name. */        public static final short QNAME = 1;        /** Type: wildcard. */        public static final short WILDCARD = 2;        /** Type: node. */        public static final short NODE = 3;        /** Type: namespace */        public static final short NAMESPACE= 4;        //        // Data        //        /** Node test type. */        public short type;        /** Node qualified name. */        public final QName name = new QName();        //        // Constructors        //        /** Constructs a node test of type WILDCARD or NODE. */        public NodeTest(short type) {            this.type = type;        } // <init>(int)        /** Constructs a node test of type QName. */        public NodeTest(QName name) {            this.type = QNAME;            this.name.setValues(name);        } // <init>(QName)        /** Constructs a node test of type Namespace. */        public NodeTest(String prefix, String uri) {            this.type = NAMESPACE;            this.name.setValues(prefix, null, null, uri);        } // <init>(String,String)        /** Copy constructor. */        public NodeTest(NodeTest nodeTest) {            type = nodeTest.type;            name.setValues(nodeTest.name);        } // <init>(NodeTest)        //        // Object methods        //        /** Returns a string representation of this object. */        public String toString() {            switch (type) {                case QNAME: {                    if (name.prefix.length() !=0) {                        if (name.uri != null) {                            return name.prefix+':'+name.localpart;                        }                        return "{"+name.uri+'}'+name.prefix+':'+name.localpart;                    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -