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


Java Node.insertBefore方法代码示例

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


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

示例1: setCellIndex

import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
public void setCellIndex( int cellIndex )
{
    Node    parent;
    Node    child;
    
    parent = getParentNode();
    if ( parent instanceof HTMLTableRowElement )
    {
        child = parent.getFirstChild();
        while ( child != null )
        {
            if ( child instanceof HTMLTableCellElement )
            {
                if ( cellIndex == 0 )
                {
                    if ( this != child )
                        parent.insertBefore( this, child );
                    return;
                }
                -- cellIndex;
            }
            child = child.getNextSibling();
        }
    }
    parent.appendChild( this );
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:27,代码来源:HTMLTableCellElementImpl.java

示例2: expandEntityRef

import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
protected final void expandEntityRef (Node parent, Node reference){
    Node kid, next;
    for (kid = reference.getFirstChild(); kid != null; kid = next) {
        next = kid.getNextSibling();
        parent.insertBefore(kid, reference);
    }
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:8,代码来源:DOMNormalizer.java

示例3: replaceRenameElement

import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
private ElementImpl replaceRenameElement(ElementImpl el, String namespaceURI, String name) {
    
    // we need to create a new object
    ElementNSImpl nel = (ElementNSImpl)createElementNS(namespaceURI, name);
    
    // register event listeners on new node
    copyEventListeners(el, nel);
    
    // remove user data from old node
    Hashtable data = removeUserDataTable(el);
    
    // remove old node from parent if any
    Node parent = el.getParentNode();
    Node nextSib = el.getNextSibling();
    if (parent != null) {
        parent.removeChild(el);
    }
    // move children to new node
    Node child = el.getFirstChild();
    while (child != null) {
        el.removeChild(child);
        nel.appendChild(child);
        child = el.getFirstChild();
    }
    // move specified attributes to new node
    nel.moveSpecifiedAttributes(el);
    
    // attach user data to new node
    setUserDataTable(nel, data);
    
    // and fire user data NODE_RENAMED event
    callUserDataHandlers(el, nel,
            UserDataHandler.NODE_RENAMED);
    
    // insert new node where old one was
    if (parent != null) {
        parent.insertBefore(nel, nextSib);
    }
    return nel;
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:41,代码来源:CoreDocumentImpl.java

示例4: splitText

import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Break a text node into two sibling nodes. (Note that if the current node
 * has no parent, they won't wind up as "siblings" -- they'll both be
 * orphans.)
 * 
 * @param offset
 *            The offset at which to split. If offset is at the end of the
 *            available data, the second node will be empty.
 * 
 * @return A reference to the new node (containing data after the offset
 *         point). The original node will contain data up to that point.
 * 
 * @throws DOMException(INDEX_SIZE_ERR)
 *             if offset is <0 or >length.
 * 
 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR)
 *             if node is read-only.
 */
public Text splitText(int offset) 
    throws DOMException {

    if (isReadOnly()) {
        throw new DOMException(
        DOMException.NO_MODIFICATION_ALLOWED_ERR, 
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null));
    }

    if (needsSyncData()) {
        synchronizeData();
    }
    if (offset < 0 || offset > data.length() ) {
        throw new DOMException(DOMException.INDEX_SIZE_ERR, 
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
    }
        
    // split text into two separate nodes
    Text newText =
        getOwnerDocument().createTextNode(data.substring(offset));
    setNodeValue(data.substring(0, offset));

    // insert new text node
    Node parentNode = getParentNode();
    if (parentNode != null) {
        parentNode.insertBefore(newText, nextSibling);
    }

    return newText;

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

示例5: writeToDOM

import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
private synchronized void writeToDOM(Node target, short type) {
    Document futureOwner = (type == XSAnnotation.W3C_DOM_ELEMENT) ? 
            target.getOwnerDocument() : (Document)target;
    DOMParser parser = fGrammar.getDOMParser();
    StringReader aReader = new StringReader(fData);
    InputSource aSource = new InputSource(aReader);
    try {
        parser.parse(aSource);
    } 
    catch (SAXException e) {
        // this should never happen!
        // REVISIT:  what to do with this?; should really not
        // eat it...
    } 
    catch (IOException i) {
        // ditto with above
    }
    Document aDocument = parser.getDocument();
    parser.dropDocumentReferences();
    Element annotation = aDocument.getDocumentElement();
    Node newElem = null;
    if (futureOwner instanceof CoreDocumentImpl) {
        newElem = futureOwner.adoptNode(annotation);
        // adoptNode will return null when the DOM implementations are not compatible.
        if (newElem == null) {
            newElem = futureOwner.importNode(annotation, true);
        }
    }
    else {
        newElem = futureOwner.importNode(annotation, true);
    }
    target.insertBefore(newElem, target.getFirstChild());
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:34,代码来源:XSAnnotationImpl.java

示例6: getHead

import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Obtains the &lt;HEAD&gt; element in the document, creating one if does
 * not exist before. The &lt;HEAD&gt; element is the first element in the
 * &lt;HTML&gt; in the document. The &lt;HTML&gt; element is obtained by
 * calling {@link #getDocumentElement}. If the element does not exist, one
 * is created.
 * <P>
 * Called by {@link #getTitle}, {@link #setTitle}, {@link #getBody} and
 * {@link #setBody} to assure the document has the &lt;HEAD&gt; element
 * correctly placed.
 *
 * @return The &lt;HEAD&gt; element
 */
public synchronized HTMLElement getHead()
{
    Node    head;
    Node    html;
    Node    child;
    Node    next;

    // Call getDocumentElement() to get the HTML element that is also the
    // top-level element in the document. Get the first element in the
    // document that is called HEAD. Work with that.
    html = getDocumentElement();
    synchronized ( html )
    {
        head = html.getFirstChild();
        while ( head != null && ! ( head instanceof HTMLHeadElement ) )
            head = head.getNextSibling();
        // HEAD exists but might not be first element in HTML: make sure
        // it is and return it.
        if ( head != null )
        {
            synchronized ( head )
            {
                child = html.getFirstChild();
                while ( child != null && child != head )
                {
                    next = child.getNextSibling();
                    head.insertBefore( child, head.getFirstChild() );
                    child = next;
                }
            }
            return (HTMLElement) head;
        }

        // Head does not exist, create a new one, place it at the top of the
        // HTML element and return it.
        head = new HTMLHeadElementImpl( this, "HEAD" );
        html.insertBefore( head, html.getFirstChild() );
    }
    return (HTMLElement) head;
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:54,代码来源:HTMLDocumentImpl.java

示例7: getBody

import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
public synchronized HTMLElement getBody()
{
    Node    html;
    Node    head;
    Node    body;
    Node    child;
    Node    next;

    // Call getDocumentElement() to get the HTML element that is also the
    // top-level element in the document. Get the first element in the
    // document that is called BODY. Work with that.
    html = getDocumentElement();
    head = getHead();
    synchronized ( html )
    {
        body = head.getNextSibling();
        while ( body != null && ! ( body instanceof HTMLBodyElement )
                && ! ( body instanceof HTMLFrameSetElement ) )
            body = body.getNextSibling();

        // BODY/FRAMESET exists but might not be second element in HTML
        // (after HEAD): make sure it is and return it.
        if ( body != null )
        {
            synchronized ( body )
            {
                child = head.getNextSibling();
                while ( child != null && child != body )
                {
                    next = child.getNextSibling();
                    body.insertBefore( child, body.getFirstChild() );
                    child = next;
                }
            }
            return (HTMLElement) body;
        }

        // BODY does not exist, create a new one, place it in the HTML element
        // right after the HEAD and return it.
        body = new HTMLBodyElementImpl( this, "BODY" );
        html.appendChild( body );
    }
    return (HTMLElement) body;
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:45,代码来源:HTMLDocumentImpl.java

示例8: setBody

import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
public synchronized void setBody( HTMLElement newBody )
{
    Node    html;
    Node    body;
    Node    head;
    Node    child;
    NodeList list;

    synchronized ( newBody )
    {
        // Call getDocumentElement() to get the HTML element that is also the
        // top-level element in the document. Get the first element in the
        // document that is called BODY. Work with that.
        html = getDocumentElement();
        head = getHead();
        synchronized ( html )
        {
            list = this.getElementsByTagName( "BODY" );
            if ( list.getLength() > 0 ) {
                // BODY exists but might not follow HEAD in HTML. If not,
                // make it so and replce it. Start with the HEAD and make
                // sure the BODY is the first element after the HEAD.
                body = list.item( 0 );
                synchronized ( body )
                {
                    child = head;
                    while ( child != null )
                    {
                        if ( child instanceof Element )
                        {
                            if ( child != body )
                                html.insertBefore( newBody, child );
                            else
                                html.replaceChild( newBody, body );
                            return;
                        }
                        child = child.getNextSibling();
                    }
                    html.appendChild( newBody );
                }
                return;
            }
            // BODY does not exist, place it in the HTML element
            // right after the HEAD.
            html.appendChild( newBody );
        }
    }
}
 
开发者ID:MaTriXy,项目名称:xerces-for-android,代码行数:49,代码来源:HTMLDocumentImpl.java


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