本文整理匯總了Java中org.w3c.dom.Node.getLastChild方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.getLastChild方法的具體用法?Java Node.getLastChild怎麽用?Java Node.getLastChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.getLastChild方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLastChildElementNS
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Finds and returns the last child node with the given qualified name. */
public static Element getLastChildElementNS(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++) {
String uri = child.getNamespaceURI();
if (uri != null && uri.equals(elemNames[i][0]) &&
child.getLocalName().equals(elemNames[i][1])) {
return (Element)child;
}
}
}
child = child.getPreviousSibling();
}
// not found
return null;
}
示例2: insertSourceMarkers
import org.w3c.dom.Node; //導入方法依賴的package包/類
private static File insertSourceMarkers(@NonNull Node node, @Nullable File currentFile) {
for (int i = 0; i < node.getChildNodes().getLength(); i++) {
Node child = node.getChildNodes().item(i);
short nodeType = child.getNodeType();
if (nodeType == Node.ELEMENT_NODE
|| nodeType == Node.COMMENT_NODE
|| nodeType == Node.DOCUMENT_NODE
|| nodeType == Node.CDATA_SECTION_NODE) {
File file = MergerXmlUtils.getFileFor(child);
if (file != null && !file.equals(currentFile)) {
i += insertSourceMarker(node, child, file, false);
currentFile = file;
}
currentFile = insertSourceMarkers(child, currentFile);
}
}
Node lastElement = node.getLastChild();
while (lastElement != null && lastElement.getNodeType() == Node.TEXT_NODE) {
lastElement = lastElement.getPreviousSibling();
}
if (lastElement != null && lastElement.getNodeType() == Node.ELEMENT_NODE) {
File parentFile = MergerXmlUtils.getFileFor(node);
File lastFile = MergerXmlUtils.getFileFor(lastElement);
if (lastFile != null && parentFile != null && !parentFile.equals(lastFile)) {
insertSourceMarker(node, lastElement, parentFile, true);
currentFile = parentFile;
}
}
return currentFile;
}
示例3: getLastChildElement
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Finds and returns the last child node with the given name. */
public static Element getLastChildElement(Node parent, String elemName) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (child.getNodeName().equals(elemName)) {
return (Element)child;
}
}
child = child.getPreviousSibling();
}
// not found
return null;
}
示例4: getLastChildElement
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Finds and returns the last child element node.
* Overload previous method for non-Xerces node impl.
*/
public static Element getLastChildElement(Node parent) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
return (Element)child;
}
child = child.getPreviousSibling();
}
// not found
return null;
}
示例5: getLastVisibleChildElement
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Finds and returns the last visible child element node. */
public static Element getLastVisibleChildElement(Node parent) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
!isHidden(child)) {
return (Element)child;
}
child = child.getPreviousSibling();
}
// not found
return null;
}
示例6: getLastElementChild
import org.w3c.dom.Node; //導入方法依賴的package包/類
private Element getLastElementChild(Node n) {
final Node top = n;
while (n != null) {
if (n.getNodeType() == Node.ELEMENT_NODE) {
return (Element) n;
}
Node next = n.getLastChild();
while (next == null) {
if (top == n) {
break;
}
next = n.getPreviousSibling();
if (next == null) {
n = n.getParentNode();
if (n == null || top == n) {
return null;
}
}
}
n = next;
}
return null;
}
示例7: getLastChildElementNS
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** 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;
}
示例8: getLastVisibleChildElement
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Finds and returns the last visible child element node.
* Overload previous method for non-Xerces node impl
*/
public static Element getLastVisibleChildElement(Node parent, Map<Node, String> 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;
}
示例9: getLastChild
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Internal function.
* Return the last child Node, from the input node
* after applying filter, whatToshow.
* The current node is not consulted or set.
*/
Node getLastChild(Node node) {
if (node == null) return null;
if ( !fEntityReferenceExpansion
&& node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
return null;
Node newNode = node.getLastChild();
if (newNode == null) return null;
int accept = acceptNode(newNode);
if (accept == NodeFilter.FILTER_ACCEPT)
return newNode;
else
if (accept == NodeFilter.FILTER_SKIP
&& newNode.hasChildNodes())
{
Node lChild = getLastChild(newNode);
if (lChild == null) {
return getPreviousSibling(newNode, node);
}
return lChild;
}
else
//if (accept == NodeFilter.REJECT_NODE)
{
return getPreviousSibling(newNode, node);
}
}
示例10: previousNode
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** The method previousNode(Node) returns the previous node
* from the actual DOM tree.
*/
Node previousNode(Node node) {
Node result;
// if we're at the root, return null.
if (node == fRoot) return null;
// get sibling
result = node.getPreviousSibling();
if (result == null) {
//if 1st sibling, return parent
result = node.getParentNode();
return result;
}
// if sibling has children, keep getting last child of child.
if (result.hasChildNodes()
&& !(!fEntityReferenceExpansion
&& result != null
&& result.getNodeType() == Node.ENTITY_REFERENCE_NODE))
{
while (result.hasChildNodes()) {
result = result.getLastChild();
}
}
return result;
}
示例11: convertToFinalForm
import org.w3c.dom.Node; //導入方法依賴的package包/類
private static void convertToFinalForm(Node program) throws TransformerException
{
Element functions = doc.createElement("functions");
Element dataStructures = doc.createElement("structures");
Element init = doc.createElement("init");
removeFunctions(program, functions);
removeDataStructures(program, dataStructures);
Node initCode = program.getFirstChild();
Node globalVariable = initCode.getLastChild();
while (globalVariable.getNodeName().equals("uses"))
{
dataStructures.appendChild(globalVariable.cloneNode(true));
globalVariable = globalVariable.getPreviousSibling();
initCode.removeChild(globalVariable.getNextSibling());
}
init.appendChild(initCode.cloneNode(true));
while (program.hasChildNodes())
program.removeChild(program.getFirstChild());
NodeList myFunctions = functions.getChildNodes();
for (int i = 0; i < myFunctions.getLength();i++)
{
for (Node temp = myFunctions.item(i).getLastChild();temp != null;temp = temp.getPreviousSibling())
{
if (temp.getLastChild().getTextContent().equals(myFunctions.item(i).getFirstChild().getTextContent()))
{
myFunctions.item(i).removeChild(temp);
break;
}
}
}
Element callMain = doc.createElement("op");
callMain.setAttribute("name", "CALL");
callMain.setAttribute("type", "void");
Element mainName = doc.createElement("value");
mainName.setTextContent("main");
callMain.appendChild(mainName);
Element mainParams = doc.createElement("op");
mainParams.setAttribute("name", "NO_ARG");
mainParams.setAttribute("type", "");
callMain.appendChild(mainParams);
init.appendChild(callMain);
Element haltProgram = doc.createElement("op");
haltProgram.setAttribute("name", "HALT");
init.appendChild(haltProgram);
program.appendChild(init);
program.appendChild(functions);
program.appendChild(dataStructures);
}
示例12: setStructIndices
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static void setStructIndices(Node program)
{
Node structures = program.getLastChild();
for (Node n = structures.getFirstChild(); n != null; n = n.getNextSibling())
{
if (n.getNodeName().equals("data"))
{
String kind = n.getAttributes().getNamedItem("kind").getTextContent();
if (kind.equals("STRUCT"))
{
int totalSize = 0;
for (Node child = n.getLastChild(); !child.getNodeName().equals("value"); child = child.getPreviousSibling())
{
TreeToAE2.setIndexOf("struct " + n.getFirstChild().getTextContent(), child.getLastChild().getTextContent(), totalSize);
try
{
totalSize += TreeToAE2.getSizeOf(child.getFirstChild().getTextContent());
}
catch(Exception e)
{
}
}
}
else if (kind.equals("UNION"))
{
for (Node child = n.getLastChild(); !child.getNodeName().equals("value"); child = child.getPreviousSibling())
{
TreeToAE2.setIndexOf("union " + n.getFirstChild().getTextContent(), child.getLastChild().getTextContent(), 0);
}
}
else if (kind.equals("ENUM"))
{
int i = 0;
for (Node child = n.getLastChild(); !child.getNodeName().equals("value"); child = child.getPreviousSibling())
{
TreeToAE2.setIndexOf("union " + n.getFirstChild().getTextContent(), child.getLastChild().getTextContent(), i);
i++;
}
}
}
}
}
示例13: synchronizeData
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Synchronizes the node's data. */
protected void synchronizeData() {
// no need to sync in the future
needsSyncData(false);
// fluff up enough nodes to fill identifiers hash
if (fIdElement != null) {
// REVISIT: There has to be a more efficient way of
// doing this. But keep in mind that the
// tree can have been altered and re-ordered
// before all of the element nodes with ID
// attributes have been registered. For now
// this is reasonable and safe. -Ac
IntVector path = new IntVector();
for (int i = 0; i < fIdCount; i++) {
// ignore if it's already been registered
int elementNodeIndex = fIdElement[i];
String idName = fIdName[i];
if (idName == null) {
continue;
}
// find path from this element to the root
path.removeAllElements();
int index = elementNodeIndex;
do {
path.addElement(index);
int pchunk = index >> CHUNK_SHIFT;
int pindex = index & CHUNK_MASK;
index = getChunkIndex(fNodeParent, pchunk, pindex);
} while (index != -1);
// Traverse path (backwards), fluffing the elements
// along the way. When this loop finishes, "place"
// will contain the reference to the element node
// we're interested in. -Ac
Node place = this;
for (int j = path.size() - 2; j >= 0; j--) {
index = path.elementAt(j);
Node child = place.getLastChild();
while (child != null) {
if (child instanceof DeferredNode) {
int nodeIndex =
((DeferredNode)child).getNodeIndex();
if (nodeIndex == index) {
place = child;
break;
}
}
child = child.getPreviousSibling();
}
}
// register the element
Element element = (Element)place;
putIdentifier0(idName, element);
fIdName[i] = null;
// see if there are more IDs on this element
while (i + 1 < fIdCount &&
fIdElement[i + 1] == elementNodeIndex) {
idName = fIdName[++i];
if (idName == null) {
continue;
}
putIdentifier0(idName, element);
}
}
} // if identifiers
}
示例14: getLastChildElement
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Returns the last child element of the specified node, or null if there
* is no such element.
*
* @param node the node
* @return the last child element of the specified node, or null if there
* is no such element
* @throws NullPointerException if <code>node == null</code>
*/
public static Element getLastChildElement(Node node) {
Node child = node.getLastChild();
while (child != null && child.getNodeType() != Node.ELEMENT_NODE) {
child = child.getPreviousSibling();
}
return (Element)child;
}