Exemple #1
0
        internal static Node Get(ANode aNode)
        {
            if (aNode == null)
            {
                throw new ArgumentNullException("aNode");
            }

            // Is this a database node?
            DBNode dbNode = aNode as DBNode;

            if (dbNode != null)
            {
                Database database = Database.Get(dbNode.data());
                return(Get(dbNode, database));
            }

            // If not, create the appropriate non-database node class
            NodeType nodeType = aNode.nodeType();

            if (nodeType == org.basex.query.item.NodeType.ELM)
            {
                return(new Element(aNode, null));
            }
            if (nodeType == org.basex.query.item.NodeType.TXT)
            {
                return(new Text(aNode, null));
            }
            if (nodeType == org.basex.query.item.NodeType.ATT)
            {
                return(new Attribute(aNode, null));
            }
            if (nodeType == org.basex.query.item.NodeType.DOC)
            {
                return(new Document(aNode, null));
            }
            if (nodeType == org.basex.query.item.NodeType.COM)
            {
                return(new Comment(aNode, null));
            }
            if (nodeType == org.basex.query.item.NodeType.PI)
            {
                return(new ProcessingInstruction(aNode, null));
            }
            throw new ArgumentException("Invalid node type");
        }
Exemple #2
0
        private readonly Database _database = null; // Cache the database that this node belongs to

        #region Construction

        protected Node(ANode aNode, int kind, Database database)
        {
            _dbNode = aNode as DBNode;
            if (aNode == null)
            {
                throw new ArgumentNullException("aNode");
            }
            if (aNode.kind() != kind)
            {
                throw new ArgumentException("Incorrect node type");
            }
            _aNode    = aNode;
            _fNode    = aNode as FNode;
            _kind     = kind;
            _database = database;
            if (_dbNode != null)
            {
                _id = _dbNode.data().id(_dbNode.pre);
            }
        }