本文整理汇总了Java中mf.org.w3c.dom.Node.ELEMENT_NODE属性的典型用法代码示例。如果您正苦于以下问题:Java Node.ELEMENT_NODE属性的具体用法?Java Node.ELEMENT_NODE怎么用?Java Node.ELEMENT_NODE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类mf.org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.ELEMENT_NODE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLastChildElement
/** Finds and returns the last child node with the given name. */
public static Element getLastChildElement(Node parent, String elemNames[]) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
for (int i = 0; i < elemNames.length; i++) {
if (child.getNodeName().equals(elemNames[i])) {
return (Element)child;
}
}
}
child = child.getPreviousSibling();
}
// not found
return null;
}
示例2: getLastElementChild
/**
* @see <a href="http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/#attribute-lastElementChild">
* Element Traversal Specification</a>
*/
public final Element getLastElementChild() {
Node n = getLastChild();
while (n != null) {
switch (n.getNodeType()) {
case Node.ELEMENT_NODE:
return (Element) n;
case Node.ENTITY_REFERENCE_NODE:
final Element e = getLastElementChild(n);
if (e != null) {
return e;
}
break;
}
n = n.getPreviousSibling();
}
return null;
}
示例3: getNextSiblingElement
/** Finds and returns the next sibling node with the given name. */
public static Element getNextSiblingElement(Node node, String elemNames[]) {
// search for node
Node sibling = node.getNextSibling();
while (sibling != null) {
if (sibling.getNodeType() == Node.ELEMENT_NODE) {
for (int i = 0; i < elemNames.length; i++) {
if (sibling.getNodeName().equals(elemNames[i])) {
return (Element)sibling;
}
}
}
sibling = sibling.getNextSibling();
}
// not found
return null;
}
示例4: getPreviousElementSibling
/**
* @see <a href="http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/#attribute-previousElementSibling">
* Element Traversal Specification</a>
*/
public final Element getPreviousElementSibling() {
Node n = getPreviousLogicalSibling(this);
while (n != null) {
switch (n.getNodeType()) {
case Node.ELEMENT_NODE:
return (Element) n;
case Node.ENTITY_REFERENCE_NODE:
final Element e = getLastElementChild(n);
if (e != null) {
return e;
}
break;
}
n = getPreviousLogicalSibling(n);
}
return null;
}
示例5: getFirstElementChild
private Element getFirstElementChild(Node n) {
final Node top = n;
while (n != null) {
if (n.getNodeType() == Node.ELEMENT_NODE) {
return (Element) n;
}
Node next = n.getFirstChild();
while (next == null) {
if (top == n) {
break;
}
next = n.getNextSibling();
if (next == null) {
n = n.getParentNode();
if (n == null || top == n) {
return null;
}
}
}
n = next;
}
return null;
}
示例6: getNextSiblingElementNS
/** Finds and returns the next sibling node with the given qualified name. */
public static Element getNextSiblingElementNS(Node node,
String[][] elemNames) {
// search for node
Node sibling = node.getNextSibling();
while (sibling != null) {
if (sibling.getNodeType() == Node.ELEMENT_NODE) {
for (int i = 0; i < elemNames.length; i++) {
String uri = sibling.getNamespaceURI();
if (uri != null && uri.equals(elemNames[i][0]) &&
sibling.getLocalName().equals(elemNames[i][1])) {
return (Element)sibling;
}
}
}
sibling = sibling.getNextSibling();
}
// not found
return null;
}
示例7: getFirstChildElementNS
/** Finds and returns the first child node with the given qualified name. */
public static Element getFirstChildElementNS(Node parent,
String uri, String localpart) {
// search for node
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String childURI = child.getNamespaceURI();
if (childURI != null && childURI.equals(uri) &&
child.getLocalName().equals(localpart)) {
return (Element)child;
}
}
child = child.getNextSibling();
}
// not found
return null;
}
示例8: getLastChildElementNS
/** Finds and returns the last child node with the given qualified name. */
public static Element getLastChildElementNS(Node parent,
String uri, String localpart) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String childURI = child.getNamespaceURI();
if (childURI != null && childURI.equals(uri) &&
child.getLocalName().equals(localpart)) {
return (Element)child;
}
}
child = child.getPreviousSibling();
}
// not found
return null;
}
示例9: getLastVisibleChildElement
/** Finds and returns the last visible child element node.
* Overload previous method for non-Xerces node impl
*/
public static Element getLastVisibleChildElement(Node parent, Hashtable hiddenNodes) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
!isHidden(child, hiddenNodes)) {
return (Element)child;
}
child = child.getPreviousSibling();
}
// not found
return null;
}
示例10: isKidOK
/**
* Uses the kidOK lookup table to check whether the proposed
* tree structure is legal.
*/
protected boolean isKidOK(Node parent, Node child) {
if (allowGrammarAccess &&
parent.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
return child.getNodeType() == Node.ELEMENT_NODE;
}
return 0 != (kidOK[parent.getNodeType()] & 1 << child.getNodeType());
}
示例11: ElementImpl
public ElementImpl(int line, int column, int offset) {
row = -1;
col = -1;
parentRow = -1;
nodeType = Node.ELEMENT_NODE;
this.line = line;
this.column = column;
charOffset = offset;
}
示例12: handleBaseURI
/**
* Record baseURI information for the Element (by adding xml:base attribute)
* or for the ProcessingInstruction (by setting a baseURI field)
* Non deferred DOM.
*
* @param node
*/
protected final void handleBaseURI (Node node){
if (fDocumentImpl != null) {
// REVISIT: remove dependency on our implementation when
// DOM L3 becomes REC
String baseURI = null;
short nodeType = node.getNodeType ();
if (nodeType == Node.ELEMENT_NODE) {
// if an element already has xml:base attribute
// do nothing
if (fNamespaceAware) {
if (((Element)node).getAttributeNodeNS ("http://www.w3.org/XML/1998/namespace","base")!=null) {
return;
}
} else if (((Element)node).getAttributeNode ("xml:base") != null) {
return;
}
// retrive the baseURI from the entity reference
baseURI = ((EntityReferenceImpl)fCurrentNode).getBaseURI ();
if (baseURI !=null && !baseURI.equals (fDocumentImpl.getDocumentURI ())) {
if (fNamespaceAware) {
((Element)node).setAttributeNS ("http://www.w3.org/XML/1998/namespace", "xml:base", baseURI);
} else {
((Element)node).setAttribute ("xml:base", baseURI);
}
}
}
else if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) {
baseURI = ((EntityReferenceImpl)fCurrentNode).getBaseURI ();
if (baseURI !=null && fErrorHandler != null) {
DOMErrorImpl error = new DOMErrorImpl ();
error.fType = "pi-base-uri-not-preserved";
error.fRelatedData = baseURI;
error.fSeverity = DOMError.SEVERITY_WARNING;
fErrorHandler.getErrorHandler ().handleError (error);
}
}
}
}
示例13: normalize
/**
* In "normal form" (as read from a source file), there will never be two
* Text children in succession. But DOM users may create successive Text
* nodes in the course of manipulating the document. Normalize walks the
* sub-tree and merges adjacent Texts, as if the DOM had been written out
* and read back in again. This simplifies implementation of higher-level
* functions that may want to assume that the document is in standard form.
* <p>
* To normalize a Document, normalize its top-level Element child.
* <p>
* As of PR-DOM-Level-1-19980818, CDATA -- despite being a subclass of
* Text -- is considered "markup" and will _not_ be merged either with
* normal Text or with other CDATASections.
*/
public void normalize() {
// No need to normalize if already normalized.
if (isNormalized()) {
return;
}
if (needsSyncChildren()) {
synchronizeChildren();
}
ChildNode kid, next;
for (kid = firstChild; kid != null; kid = next) {
next = kid.nextSibling;
// 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 );
}
}
}
// Otherwise it might be an Element, which is handled recursively
else if (kid.getNodeType() == Node.ELEMENT_NODE) {
kid.normalize();
}
}
// We must also normalize all of the attributes
if ( attributes!=null )
{
for( int i=0; i<attributes.getLength(); ++i )
{
Node attr = attributes.item(i);
attr.normalize();
}
}
// changed() will have occurred when the removeChild() was done,
// so does not have to be reissued.
isNormalized(true);
}
示例14: synchronizeChildren
/**
* Synchronizes the node's children with the internal structure.
* Fluffing the children at once solves a lot of work to keep
* the two structures in sync. The problem gets worse when
* editing the tree -- this makes it a lot easier.
*/
protected void synchronizeChildren() {
if (needsSyncData()) {
synchronizeData();
/*
* when we have elements with IDs this method is being recursively
* called from synchronizeData, in which case we've already gone
* through the following and we can now simply stop here.
*/
if (!needsSyncChildren()) {
return;
}
}
// we don't want to generate any event for this so turn them off
boolean orig = mutationEvents;
mutationEvents = false;
// no need to sync in the future
needsSyncChildren(false);
getNodeType(0);
// create children and link them as siblings
ChildNode first = null;
ChildNode last = null;
for (int index = getLastChild(0);
index != -1;
index = getPrevSibling(index)) {
ChildNode node = (ChildNode)getNodeObject(index);
if (last == null) {
last = node;
}
else {
first.previousSibling = node;
}
node.ownerNode = this;
node.isOwned(true);
node.nextSibling = first;
first = node;
// save doctype and document type
int type = node.getNodeType();
if (type == Node.ELEMENT_NODE) {
docElement = (ElementImpl)node;
}
else if (type == Node.DOCUMENT_TYPE_NODE) {
docType = (DocumentTypeImpl)node;
}
}
if (first != null) {
firstChild = first;
first.isFirstChild(true);
lastChild(last);
}
// set mutation events flag back to its original value
mutationEvents = orig;
}
示例15: lookupPrefix
/**
*
* DOM Level 3 - Experimental:
* Look up the prefix associated to the given namespace URI, starting from this node.
*
* @param namespaceURI
* @return the prefix for the namespace
*/
public String lookupPrefix(String namespaceURI){
// REVISIT: When Namespaces 1.1 comes out this may not be true
// Prefix can't be bound to null namespace
if (namespaceURI == null) {
return null;
}
short type = this.getNodeType();
switch (type) {
case Node.ELEMENT_NODE: {
this.getNamespaceURI(); // to flip out children
return lookupNamespacePrefix(namespaceURI, (ElementImpl)this);
}
case Node.DOCUMENT_NODE:{
return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI);
}
case Node.ENTITY_NODE :
case Node.NOTATION_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
case Node.DOCUMENT_TYPE_NODE:
// type is unknown
return null;
case Node.ATTRIBUTE_NODE:{
if (this.ownerNode.getNodeType() == Node.ELEMENT_NODE) {
return ownerNode.lookupPrefix(namespaceURI);
}
return null;
}
default:{
NodeImpl ancestor = (NodeImpl)getElementAncestor(this);
if (ancestor != null) {
return ancestor.lookupPrefix(namespaceURI);
}
return null;
}
}
}