本文整理匯總了Java中org.w3c.dom.Node.getFirstChild方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.getFirstChild方法的具體用法?Java Node.getFirstChild怎麽用?Java Node.getFirstChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.getFirstChild方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: giveVariablesAddressesInNode
import org.w3c.dom.Node; //導入方法依賴的package包/類
private static int giveVariablesAddressesInNode(Node node, int index) {
for (Node child = node.getFirstChild();child != null;child = child.getNextSibling())
{
if (child.getNodeName().equals("uses"))
{
Element element = (Element) child;
element.setAttribute("address", "V" + index);
try {
index += TreeToAE2.getSizeOf(child.getFirstChild().getTextContent());
} catch (Exception e) {
e.printStackTrace();
}
}
else
{
index = giveVariablesAddressesInNode(child,index);
}
}
return index;
}
示例2: findNode
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Returns the first node where attr equals value. This implementation does not use XPath.
*/
public static Node findNode(Node node, String attr, String value) {
String tmp = (node instanceof Element) ? ((Element) node).getAttribute(attr) : null;
if (tmp != null && tmp.equals(value)) {
return node;
}
node = node.getFirstChild();
while (node != null) {
Node result = findNode(node, attr, value);
if (result != null) {
return result;
}
node = node.getNextSibling();
}
return null;
}
示例3: parseDisplayColumns
import org.w3c.dom.Node; //導入方法依賴的package包/類
void parseDisplayColumns(Node columnsNode, Database db) {
for (Node child = columnsNode.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() != Node.ELEMENT_NODE)
continue;
final String nodeName = child.getNodeName();
ParsedColInfo col = new ParsedColInfo();
col.expression = parseExpressionTree(child, db);
ExpressionUtil.assignLiteralConstantTypesRecursively(col.expression);
ExpressionUtil.assignOutputValueTypesRecursively(col.expression);
assert(col.expression != null);
col.alias = child.getAttributes().getNamedItem("alias").getNodeValue();
if (nodeName.equals("columnref")) {
col.columnName =
child.getAttributes().getNamedItem("column").getNodeValue();
col.tableName =
child.getAttributes().getNamedItem("table").getNodeValue();
}
col.index = allColumns.size();
displayColumns.add(col);
allColumns.put(col.alias, col);
}
}
示例4: mergeJFIFsubtree
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Merge a JFIF subtree into the marker sequence, if the subtree
* is non-empty.
* If a JFIF marker exists, update it from the subtree.
* If none exists, create one from the subtree and insert it at the
* beginning of the marker sequence.
*/
private void mergeJFIFsubtree(Node JPEGvariety)
throws IIOInvalidTreeException {
if (JPEGvariety.getChildNodes().getLength() != 0) {
Node jfifNode = JPEGvariety.getFirstChild();
// is there already a jfif marker segment?
JFIFMarkerSegment jfifSeg =
(JFIFMarkerSegment) findMarkerSegment(JFIFMarkerSegment.class, true);
if (jfifSeg != null) {
jfifSeg.updateFromNativeNode(jfifNode, false);
} else {
// Add it as the first element in the list.
markerSequence.add(0, new JFIFMarkerSegment(jfifNode));
}
}
}
示例5: findChild
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Helper method used by {@link #findAlternateToolsXml(InputStream)} to find a given
* element child in a root XML node.
*/
private Element findChild(Node rootNode, Node after, String prefix, String[] nodeNames) {
for (int i = 0; i < nodeNames.length; i++) {
if (nodeNames[i].indexOf(':') < 0) {
nodeNames[i] = prefix + ":" + nodeNames[i];
}
}
Node child = after == null ? rootNode.getFirstChild() : after.getNextSibling();
for(; child != null; child = child.getNextSibling()) {
if (child.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
for (String nodeName : nodeNames) {
if (nodeName.equals(child.getNodeName())) {
return (Element) child;
}
}
}
return null;
}
示例6: getFirstChild
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Returns the first child element with the given XML local name.
* If xmlLocalName is null, returns the very first child element.
*/
private Node getFirstChild(Node node, String nsUri, String xmlLocalName) {
for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
nsUri.equals(child.getNamespaceURI())) {
if (xmlLocalName == null || child.getLocalName().equals(xmlLocalName)) {
return child;
}
}
}
return null;
}
示例7: getFirstChild
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Internal function.
* Return the first child Node, from the input node
* after applying filter, whatToshow.
* The current node is not consulted or set.
*/
Node getFirstChild(Node node) {
if (node == null) return null;
if ( !fEntityReferenceExpansion
&& node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
return null;
Node newNode = node.getFirstChild();
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 fChild = getFirstChild(newNode);
if (fChild == null) {
return getNextSibling(newNode, node);
}
return fChild;
}
else
//if (accept == NodeFilter.REJECT_NODE)
{
return getNextSibling(newNode, node);
}
}
示例8: setFromNativeTree
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void setFromNativeTree(Node root) throws IIOInvalidTreeException {
if (resetSequence == null) {
resetSequence = markerSequence;
}
markerSequence = new ArrayList<>();
// Build a whole new marker sequence from the tree
String name = root.getNodeName();
if (name != ((isStream) ? JPEG.nativeStreamMetadataFormatName
: JPEG.nativeImageMetadataFormatName)) {
throw new IIOInvalidTreeException("Invalid root node name: " + name,
root);
}
if (!isStream) {
if (root.getChildNodes().getLength() != 2) { // JPEGvariety and markerSequence
throw new IIOInvalidTreeException(
"JPEGvariety and markerSequence nodes must be present", root);
}
Node JPEGvariety = root.getFirstChild();
if (JPEGvariety.getChildNodes().getLength() != 0) {
markerSequence.add(new JFIFMarkerSegment(JPEGvariety.getFirstChild()));
}
}
Node markerSequenceNode = isStream ? root : root.getLastChild();
setFromMarkerSequenceNode(markerSequenceNode);
}
示例9: getChildrenByTagName
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static List<Element> getChildrenByTagName(
Node parent,
String name ) {
List<Element> nodeList = new ArrayList<Element>();
for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE && name.equals(child.getNodeName())) {
nodeList.add((Element) child);
}
}
return nodeList;
}
示例10: parseCategory
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void parseCategory(Node n)
{
final int cat = parseInteger(n.getAttributes(), "id");
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("commands".equalsIgnoreCase(d.getNodeName()))
{
parseCommands(cat, d);
}
else if ("keys".equalsIgnoreCase(d.getNodeName()))
{
parseKeys(cat, d);
}
}
}
示例11: nextNode
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** The method nextNode(Node, boolean) returns the next node
* from the actual DOM tree.
*
* The boolean visitChildren determines whether to visit the children.
* The result is the nextNode.
*/
Node nextNode(Node node, boolean visitChildren) {
if (node == null) return fRoot;
Node result;
// only check children if we visit children.
if (visitChildren) {
//if hasChildren, return 1st child.
if (node.hasChildNodes()) {
result = node.getFirstChild();
return result;
}
}
if (node == fRoot) { //if Root has no kids
return null;
}
// if hasSibling, return sibling
result = node.getNextSibling();
if (result != null) return result;
// return parent's 1st sibling.
Node parent = node.getParentNode();
while (parent != null && parent != fRoot) {
result = parent.getNextSibling();
if (result != null) {
return result;
} else {
parent = parent.getParentNode();
}
} // while (parent != null && parent != fRoot) {
// end of list, return null
return null;
}
示例12: getChild
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Get the first direct child with a given type
*/
public static Node getChild( Node parent, int type ) {
Node n=parent.getFirstChild();
while( n!=null && type != n.getNodeType() ) {
n=n.getNextSibling();
}
if( n==null ) return null;
return n;
}
示例13: expandEntityRef
import 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);
}
}
示例14: getHead
import org.w3c.dom.Node; //導入方法依賴的package包/類
public SMILElement getHead() {
Node rootElement = getDocumentElement();
Node headElement = rootElement.getFirstChild();
if (headElement == null || !(headElement instanceof SMILElement)) {
// The head doesn't exist. Create a new one.
headElement = createElement("head");
rootElement.appendChild(headElement);
}
return (SMILElement) headElement;
}
示例15: traverse
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Perform a pre-order traversal non-recursive style.
*
* Note that TreeWalker assumes that the subtree is intended to represent
* a complete (though not necessarily well-formed) document and, during a
* traversal, startDocument and endDocument will always be issued to the
* SAX listener.
*
* @param pos Node in the tree where to start traversal
*
* @throws TransformerException
*/
public void traverse(Node pos) throws org.xml.sax.SAXException
{
this.m_contentHandler.startDocument();
Node top = pos;
while (null != pos)
{
startNode(pos);
Node nextNode = pos.getFirstChild();
while (null == nextNode)
{
endNode(pos);
if (top.equals(pos))
break;
nextNode = pos.getNextSibling();
if (null == nextNode)
{
pos = pos.getParentNode();
if ((null == pos) || (top.equals(pos)))
{
if (null != pos)
endNode(pos);
nextNode = null;
break;
}
}
}
pos = nextNode;
}
this.m_contentHandler.endDocument();
}