本文整理汇总了Java中mf.org.w3c.dom.NodeList.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java NodeList.getLength方法的具体用法?Java NodeList.getLength怎么用?Java NodeList.getLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mf.org.w3c.dom.NodeList
的用法示例。
在下文中一共展示了NodeList.getLength方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTitle
import mf.org.w3c.dom.NodeList; //导入方法依赖的package包/类
public synchronized String getTitle()
{
HTMLElement head;
NodeList list;
Node title;
// Get the HEAD element and look for the TITLE element within.
// When found, make sure the TITLE is a direct child of HEAD,
// and return the title's text (the Text node contained within).
head = getHead();
list = head.getElementsByTagName( "TITLE" );
if ( list.getLength() > 0 ) {
title = list.item( 0 );
return ( (HTMLTitleElement) title ).getText();
}
// No TITLE found, return an empty string.
return "";
}
示例2: setTitle
import mf.org.w3c.dom.NodeList; //导入方法依赖的package包/类
public synchronized void setTitle( String newTitle )
{
HTMLElement head;
NodeList list;
Node title;
// Get the HEAD element and look for the TITLE element within.
// When found, make sure the TITLE is a direct child of HEAD,
// and set the title's text (the Text node contained within).
head = getHead();
list = head.getElementsByTagName( "TITLE" );
if ( list.getLength() > 0 ) {
title = list.item( 0 );
if ( title.getParentNode() != head )
head.appendChild( title );
( (HTMLTitleElement) title ).setText( newTitle );
}
else
{
// No TITLE found, create a new element and place it at the end
// of the HEAD element.
title = new HTMLTitleElementImpl( this, "TITLE" );
( (HTMLTitleElement) title ).setText( newTitle );
head.appendChild( title );
}
}
示例3: getIndex
import mf.org.w3c.dom.NodeList; //导入方法依赖的package包/类
public int getIndex()
{
Node parent;
NodeList options;
int i;
// Locate the parent SELECT. Note that this OPTION might be inside a
// OPTGROUP inside the SELECT. Or it might not have a parent SELECT.
// Everything is possible. If no parent is found, return -1.
parent = getParentNode();
while ( parent != null && ! ( parent instanceof HTMLSelectElement ) )
parent = parent.getParentNode();
if ( parent != null )
{
// Use getElementsByTagName() which creates a snapshot of all the
// OPTION elements under the SELECT. Access to the returned NodeList
// is very fast and the snapshot solves many synchronization problems.
options = ( (HTMLElement) parent ).getElementsByTagName( "OPTION" );
for ( i = 0 ; i < options.getLength() ; ++i )
if ( options.item( i ) == this )
return i;
}
return -1;
}
示例4: getSelectedIndex
import mf.org.w3c.dom.NodeList; //导入方法依赖的package包/类
public int getSelectedIndex()
{
NodeList options;
int i;
// Use getElementsByTagName() which creates a snapshot of all the
// OPTION elements under this SELECT. Access to the returned NodeList
// is very fast and the snapshot solves many synchronization problems.
// Locate the first selected OPTION and return its index. Note that
// the OPTION might be under an OPTGROUP.
options = getElementsByTagName( "OPTION" );
for ( i = 0 ; i < options.getLength() ; ++i )
if ( ( (HTMLOptionElement) options.item( i ) ).getSelected() )
return i;
return -1;
}
示例5: getRowIndex
import mf.org.w3c.dom.NodeList; //导入方法依赖的package包/类
int getRowIndex( Node parent )
{
NodeList rows;
int i;
// Use getElementsByTagName() which creates a snapshot of all the
// TR elements under the TABLE/section. Access to the returned NodeList
// is very fast and the snapshot solves many synchronization problems.
rows = ( (HTMLElement) parent ).getElementsByTagName( "TR" );
for ( i = 0 ; i < rows.getLength() ; ++i ) {
if ( rows.item( i ) == this ) {
return i;
}
}
return -1;
}
示例6: setSelectedIndex
import mf.org.w3c.dom.NodeList; //导入方法依赖的package包/类
public void setSelectedIndex( int selectedIndex )
{
NodeList options;
int i;
// Use getElementsByTagName() which creates a snapshot of all the
// OPTION elements under this SELECT. Access to the returned NodeList
// is very fast and the snapshot solves many synchronization problems.
// Change the select so all OPTIONs are off, except for the
// selectIndex-th one.
options = getElementsByTagName( "OPTION" );
for ( i = 0 ; i < options.getLength() ; ++i )
( (HTMLOptionElementImpl) options.item( i ) ).setSelected( i == selectedIndex );
}
示例7: isAttrValueWF
import mf.org.w3c.dom.NodeList; //导入方法依赖的package包/类
/** NON-DOM: check if attribute value is well-formed
* @param attributes
* @param a
* @param value
*/
public static final void isAttrValueWF(DOMErrorHandler errorHandler, DOMErrorImpl error,
DOMLocatorImpl locator, NamedNodeMap attributes, Attr a, String value, boolean xml11Version) {
if (a instanceof AttrImpl && ((AttrImpl)a).hasStringValue()) {
isXMLCharWF(errorHandler, error, locator, value, xml11Version);
} else {
NodeList children = a.getChildNodes();
//check each child node of the attribute's value
for (int j = 0; j < children.getLength(); j++) {
Node child = children.item(j);
//If the attribute's child is an entity refernce
if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
Document owner = a.getOwnerDocument();
Entity ent = null;
//search for the entity in the docType
//of the attribute's ownerDocument
if (owner != null) {
DocumentType docType = owner.getDoctype();
if (docType != null) {
NamedNodeMap entities = docType.getEntities();
ent = (Entity) entities.getNamedItemNS(
"*",
child.getNodeName());
}
}
//If the entity was not found issue a fatal error
if (ent == null) {
String msg = DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN, "UndeclaredEntRefInAttrValue",
new Object[]{a.getNodeName()});
reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR,
"UndeclaredEntRefInAttrValue");
}
}
else {
// Text node
isXMLCharWF(errorHandler, error, locator, child.getNodeValue(), xml11Version);
}
}
}
}
示例8: setBody
import mf.org.w3c.dom.NodeList; //导入方法依赖的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 );
}
}
}