当前位置: 首页>>代码示例>>Java>>正文


Java Node.TEXT_NODE属性代码示例

本文整理汇总了Java中mf.org.w3c.dom.Node.TEXT_NODE属性的典型用法代码示例。如果您正苦于以下问题:Java Node.TEXT_NODE属性的具体用法?Java Node.TEXT_NODE怎么用?Java Node.TEXT_NODE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在mf.org.w3c.dom.Node的用法示例。


在下文中一共展示了Node.TEXT_NODE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getChildText

/**
 * Returns the concatenated child text of the specified node.
 * This method only looks at the immediate children of type
 * <code>Node.TEXT_NODE</code> or the children of any child
 * node that is of type <code>Node.CDATA_SECTION_NODE</code>
 * for the concatenation.
 *
 * @param node The node to look at.
 */
public static String getChildText(Node node) {
    
    // is there anything to do?
    if (node == null) {
        return null;
    }
    
    // concatenate children text
    StringBuffer str = new StringBuffer();
    Node child = node.getFirstChild();
    while (child != null) {
        short type = child.getNodeType();
        if (type == Node.TEXT_NODE) {
            str.append(child.getNodeValue());
        }
        else if (type == Node.CDATA_SECTION_NODE) {
            str.append(getChildText(child));
        }
        child = child.getNextSibling();
    }
    
    // return text value
    return str.toString();
    
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:34,代码来源:DOMUtil.java

示例2: checkNormalizationAfterInsert

/**
 * Checks the normalized state of this node after inserting a child.
 * If the inserted child causes this node to be unnormalized, then this
 * node is flagged accordingly.
 * The conditions for changing the normalized state are:
 * <ul>
 * <li>The inserted child is a text node and one of its adjacent siblings
 * is also a text node.
 * <li>The inserted child is is itself unnormalized.
 * </ul>
 *
 * @param insertedChild the child node that was inserted into this node
 *
 * @throws NullPointerException if the inserted child is <code>null</code>
 */
void checkNormalizationAfterInsert(ChildNode insertedChild) {
    // See if insertion caused this node to be unnormalized.
    if (insertedChild.getNodeType() == Node.TEXT_NODE) {
        ChildNode prev = insertedChild.previousSibling();
        ChildNode next = insertedChild.nextSibling;
        // If an adjacent sibling of the new child is a text node,
        // flag this node as unnormalized.
        if ((prev != null && prev.getNodeType() == Node.TEXT_NODE) ||
            (next != null && next.getNodeType() == Node.TEXT_NODE)) {
            isNormalized(false);
        }
    }
    else {
        // If the new child is not normalized,
        // then this node is inherently not normalized.
        if (!insertedChild.isNormalized()) {
            isNormalized(false);
        }
    }
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:35,代码来源:AttrImpl.java

示例3: getSelectedNode

/**
 * Utility method to retrieve a child node by index.  This method
 * assumes the caller is trying to find out which node is 
 * selected by the given index.  Note that if the index is
 * greater than the number of children, this implies that the
 * first node selected is the parent node itself.
 * 
 * @param container A container node
 * 
 * @param offset    An offset within the container for which a selected node should
 *                  be computed.  If the offset is less than zero, or if the offset
 *                  is greater than the number of children, the container is returned.
 * 
 * @return Returns either a child node of the container or the
 *         container itself.
 */
private Node getSelectedNode( Node container, int offset )
{
    if ( container.getNodeType() == Node.TEXT_NODE )
        return container;

    // This case is an important convenience for 
    // traverseRightBoundary()
    if ( offset<0 )
        return container;

    Node child = container.getFirstChild();
    while( child!=null && offset > 0 )
    {
        --offset;
        child = child.getNextSibling();
    }
    if ( child!=null )
        return child;
    return container;
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:36,代码来源:RangeImpl.java

示例4: hasTextOnlyChildren

/**
 * Check if an EntityReference node has Text Only child nodes
 * 
 * @param node
 * @return true - Contains text only children
 */
private boolean hasTextOnlyChildren(Node node) {

    Node child = node;
    
    if (child == null) {
        return false;
    }
    
    child = child.getFirstChild();
    while (child != null) {
        int type = child.getNodeType();
        
        if (type == Node.ENTITY_REFERENCE_NODE) {
            return hasTextOnlyChildren(child);
        } 
        else if (type != Node.TEXT_NODE
                && type != Node.CDATA_SECTION_NODE
                && type != Node.ENTITY_REFERENCE_NODE) {
            return false;
        }
        child = child.getNextSibling();
    }
    return true;
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:30,代码来源:TextImpl.java

示例5: receiveSplitData

/** Fix up this Range if another Range has split a Text Node
 *  into 2 Nodes.
 */
void receiveSplitData(Node node, Node newNode, int offset) {
    if (node == null || newNode == null) return;
    if (fSplitNode == node) return;
    
    if (node == fStartContainer 
    && fStartContainer.getNodeType() == Node.TEXT_NODE) {
        if (fStartOffset > offset) {
            fStartOffset = fStartOffset - offset;
            fStartContainer = newNode;
        }
    }
    if (node == fEndContainer 
    && fEndContainer.getNodeType() == Node.TEXT_NODE) {
        if (fEndOffset > offset) {
            fEndOffset = fEndOffset-offset;
            fEndContainer = newNode;
        }
    }
    
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:23,代码来源:RangeImpl.java

示例6: checkIndex

void checkIndex(Node refNode, int offset) throws DOMException
{
    if (offset < 0) {
        throw new DOMException(
            DOMException.INDEX_SIZE_ERR, 
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
	}

    int type = refNode.getNodeType();
    
    // If the node contains text, ensure that the
    // offset of the range is <= to the length of the text
    if (type == Node.TEXT_NODE
        || type == Node.CDATA_SECTION_NODE
        || type == Node.COMMENT_NODE
        || type == Node.PROCESSING_INSTRUCTION_NODE) {
        if (offset > refNode.getNodeValue().length()) {
            throw new DOMException(DOMException.INDEX_SIZE_ERR, 
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
        }
    }
    else {
        // Since the node is not text, ensure that the offset
        // is valid with respect to the number of child nodes
        if (offset > refNode.getChildNodes().getLength()) {
		throw new DOMException(DOMException.INDEX_SIZE_ERR, 
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
        }
    }
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:30,代码来源:RangeImpl.java

示例7: cloneNode

/** Creates a clone of the specified node. */
public int cloneNode(int nodeIndex, boolean deep) {

    // clone immediate node
    
    int nchunk = nodeIndex >> CHUNK_SHIFT;
    int nindex = nodeIndex & CHUNK_MASK;
    int nodeType = fNodeType[nchunk][nindex];
    int cloneIndex = createNode((short)nodeType);
    int cchunk = cloneIndex >> CHUNK_SHIFT;
    int cindex = cloneIndex & CHUNK_MASK;
    setChunkValue(fNodeName, fNodeName[nchunk][nindex], cchunk, cindex);
    setChunkValue(fNodeValue, fNodeValue[nchunk][nindex], cchunk, cindex);
    setChunkValue(fNodeURI, fNodeURI[nchunk][nindex], cchunk, cindex);
    int extraIndex = fNodeExtra[nchunk][nindex];
    if (extraIndex != -1) {
        if (nodeType != Node.ATTRIBUTE_NODE && nodeType != Node.TEXT_NODE) {
            extraIndex = cloneNode(extraIndex, false);
        }
        setChunkIndex(fNodeExtra, extraIndex, cchunk, cindex);
    }

    // clone and attach children
    if (deep) {
        int prevIndex = -1;
        int childIndex = getLastChild(nodeIndex, false);
        while (childIndex != -1) {
            int clonedChildIndex = cloneNode(childIndex, deep);
            insertBefore(cloneIndex, clonedChildIndex, prevIndex);
            prevIndex = clonedChildIndex;
            childIndex = getRealPrevSibling(childIndex, false);
        }
        

    }
    
    // return cloned node index
    return cloneIndex;

}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:40,代码来源:DeferredDocumentImpl.java

示例8: getPrevSibling

/**
 * Returns the prev sibling of the given node.
 * @param free True to free sibling index.
 */
public int getPrevSibling(int nodeIndex, boolean free) {

    if (nodeIndex == -1) {
        return -1;
    }

    int chunk = nodeIndex >> CHUNK_SHIFT;
    int index = nodeIndex & CHUNK_MASK;
    int type = getChunkIndex(fNodeType, chunk, index);
    if (type == Node.TEXT_NODE) {
        do {
            nodeIndex = getChunkIndex(fNodePrevSib, chunk, index);
            if (nodeIndex == -1) {
                break;
            }
            chunk = nodeIndex >> CHUNK_SHIFT;
            index = nodeIndex & CHUNK_MASK;
            type = getChunkIndex(fNodeType, chunk, index);
        } while (type == Node.TEXT_NODE);
    }
    else {
        nodeIndex = getChunkIndex(fNodePrevSib, chunk, index);
    }

    return nodeIndex;

}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:31,代码来源:DeferredDocumentImpl.java

示例9: normalize

public void normalize() {

        // No need to normalize if already normalized or
        // if value is kept as a String.
        if (isNormalized() || hasStringValue())
            return;

        Node kid, next;
        ChildNode firstChild = (ChildNode)value;
        for (kid = firstChild; kid != null; kid = next) {
            next = kid.getNextSibling();

            // If kid is a text node, we need to check for one of two
            // conditions:
            //   1) There is an adjacent text node
            //   2) There is no adjacent text node, but kid is
            //      an empty text node.
            if ( kid.getNodeType() == Node.TEXT_NODE )
            {
                // If an adjacent text node, merge it with kid
                if ( next!=null && next.getNodeType() == Node.TEXT_NODE )
                {
                    ((Text)kid).appendData(next.getNodeValue());
                    removeChild( next );
                    next = kid; // Don't advance; there might be another.
                }
                else
                {
                    // If kid is empty, remove it
                    if ( kid.getNodeValue() == null || kid.getNodeValue().length() == 0 ) {
                        removeChild( kid );
                    }
                }
            }
        }

        isNormalized(true);
    }
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:38,代码来源:AttrImpl.java

示例10: checkNormalizationAfterRemove

/**
 * Checks the normalized of this node after removing a child.
 * If the removed child causes this node to be unnormalized, then this
 * node is flagged accordingly.
 * The conditions for changing the normalized state are:
 * <ul>
 * <li>The removed child had two adjacent siblings that were text nodes.
 * </ul>
 *
 * @param previousSibling the previous sibling of the removed child, or
 * <code>null</code>
 */
void checkNormalizationAfterRemove(ChildNode previousSibling) {
    // See if removal caused this node to be unnormalized.
    // If the adjacent siblings of the removed child were both text nodes,
    // flag this node as unnormalized.
    if (previousSibling != null &&
        previousSibling.getNodeType() == Node.TEXT_NODE) {

        ChildNode next = previousSibling.nextSibling;
        if (next != null && next.getNodeType() == Node.TEXT_NODE) {
            isNormalized(false);
        }
    }
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:25,代码来源:AttrImpl.java

示例11: getWholeTextForward

/**
 * Concatenates the text of all logically-adjacent text nodes to the 
 * right of this node
 * @param node
 * @param buffer
 * @param parent 
 * @return true - if execution was stopped because the type of node
 *         other than EntityRef, Text, CDATA is encountered, otherwise
 *         return false
 */
private boolean getWholeTextForward(Node node, StringBuffer buffer, Node parent){
	// boolean to indicate whether node is a child of an entity reference
	boolean inEntRef = false;
	
	if (parent!=null) {
		inEntRef = parent.getNodeType()==Node.ENTITY_REFERENCE_NODE;
	}
	
    while (node != null) {
        short type = node.getNodeType();
        if (type == Node.ENTITY_REFERENCE_NODE) {
            if (getWholeTextForward(node.getFirstChild(), buffer, node)){
                return true;
            }
        }
        else if (type == Node.TEXT_NODE || 
                 type == Node.CDATA_SECTION_NODE) {
            ((NodeImpl)node).getTextContent(buffer);
        }
        else {
            return true; 
        }

        node = node.getNextSibling();
    }
   
    // if the parent node is an entity reference node, must 
    // check nodes to the right of the parent entity reference node for logically adjacent
    // text nodes
    if (inEntRef) {
        getWholeTextForward(parent.getNextSibling(), buffer, parent.getParentNode());
    		return true;
    }
    
    return false;
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:46,代码来源:TextImpl.java

示例12: getWholeTextBackward

/**
 * Concatenates the text of all logically-adjacent text nodes to the left of 
 * the node
 * @param node
 * @param buffer
 * @param parent
 * @return true - if execution was stopped because the type of node
 *         other than EntityRef, Text, CDATA is encountered, otherwise
 *         return false
 */
private boolean getWholeTextBackward(Node node, StringBuffer buffer, Node parent){
	
	// boolean to indicate whether node is a child of an entity reference
	boolean inEntRef = false;
	if (parent!=null) {
		inEntRef = parent.getNodeType()==Node.ENTITY_REFERENCE_NODE;
	}
	
    while (node != null) {
        short type = node.getNodeType();
        if (type == Node.ENTITY_REFERENCE_NODE) {
            if (getWholeTextBackward(node.getLastChild(), buffer, node)){
                return true;
            }
        }
        else if (type == Node.TEXT_NODE || 
                 type == Node.CDATA_SECTION_NODE) {
            ((TextImpl)node).insertTextContent(buffer);
        }
        else {
            return true; 
        }

        node = node.getPreviousSibling();
    }
    
    // if the parent node is an entity reference node, must 
    // check nodes to the left of the parent entity reference node for logically adjacent
    // text nodes
    if (inEntRef) {
    	getWholeTextBackward(parent.getPreviousSibling(), buffer, parent.getParentNode());
        return true;
    }
    
    return false;
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:46,代码来源:TextImpl.java

示例13: saveEnclosingAttr

/**
 * NON-DOM INTERNAL: Pre-mutation context check, in
 * preparation for later generating DOMAttrModified events.
 * Determines whether this node is within an Attr
 * @param node node to get enclosing attribute for
 */
protected void saveEnclosingAttr(NodeImpl node) {
    savedEnclosingAttr = null;
    // MUTATION PREPROCESSING AND PRE-EVENTS:
    // If we're within the scope of an Attr and DOMAttrModified 
    // was requested, we need to preserve its previous value for
    // that event.
    LCount lc = LCount.lookup(MutationEventImpl.DOM_ATTR_MODIFIED);
    if (lc.total > 0) {
        NodeImpl eventAncestor = node;
        while (true) {
            if (eventAncestor == null)
                return;
            int type = eventAncestor.getNodeType();
            if (type == Node.ATTRIBUTE_NODE) {
                EnclosingAttr retval = new EnclosingAttr();
                retval.node = (AttrImpl) eventAncestor;
                retval.oldvalue = retval.node.getNodeValue();
                savedEnclosingAttr = retval;
                return;
            }
            else if (type == Node.ENTITY_REFERENCE_NODE)
                eventAncestor = eventAncestor.parentNode();
            else if (type == Node.TEXT_NODE)
                eventAncestor = eventAncestor.parentNode();
            else
                return;
            // Any other parent means we're not in an Attr
        }
    }
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:36,代码来源:DocumentImpl.java

示例14: TextImpl

public TextImpl(StringBuffer str, SchemaDOM sDOM, int row, int col) {
    fData = str.toString();
    fSchemaDOM = sDOM;
    fRow = row;
    fCol = col;
    rawname = prefix = localpart = uri = null;
    nodeType = Node.TEXT_NODE;
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:8,代码来源:TextImpl.java

示例15: hasTextContent

final boolean hasTextContent(Node child) {
    return child.getNodeType() != Node.COMMENT_NODE &&
        child.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE &&
        (child.getNodeType() != Node.TEXT_NODE ||
         ((TextImpl) child).isIgnorableWhitespace() == false);
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:6,代码来源:ParentNode.java


注:本文中的mf.org.w3c.dom.Node.TEXT_NODE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。