本文整理汇总了Java中org.w3c.dom.traversal.TreeWalker.firstChild方法的典型用法代码示例。如果您正苦于以下问题:Java TreeWalker.firstChild方法的具体用法?Java TreeWalker.firstChild怎么用?Java TreeWalker.firstChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.traversal.TreeWalker
的用法示例。
在下文中一共展示了TreeWalker.firstChild方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: traverseLevel
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private static void traverseLevel(TreeWalker walker, Element topParent, String indent) {
// describe current node:
Element current = (Element) walker.getCurrentNode();
//System.out.println(indent + "- " + ((Element) current).getTagName());
// store elements which need to be moved
if (topParent != null) {
Element parent = (Element) current.getParentNode();
if (parent != null && !topParent.equals(parent)) {
OutputFilter outputFilter = (OutputFilter)walker.getFilter();
outputFilter.getToAddList(topParent).add(current);
}
}
// traverse children:
for (Node n = walker.firstChild(); n != null; n = walker.nextSibling()) {
traverseLevel(walker, current, indent + '\t');
}
// return position to the current (level up):
walker.setCurrentNode(current);
}
示例2: parseTree
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private List<Feature> parseTree(TreeWalker walker,
String tag,
String chr,
List<Feature> features) {
Node parent = walker.getCurrentNode();
Element n = (Element) walker.firstChild();
while (n != null) {
if (n.getTagName().equalsIgnoreCase(tag)) {
Feature f = getFeature(walker, chr);
if (f != null) {
features.add(f);
}
n = (Element) walker.nextSibling();
continue;
}
parseTree(walker, tag, chr, features);
n = (Element) walker.nextSibling();
}
walker.setCurrentNode(parent);
return features;
}
示例3: setPackageToElements
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private void setPackageToElements(TreeWalker tw, String currentPackage) {
Node n = tw.getCurrentNode();
XmiElement element = new XmiElement((Element) n, this);
if (isPackageElement(element)) {
if (currentPackage.isEmpty()) {
currentPackage = element.getNameTag();
} else {
currentPackage = currentPackage + XmiTags.SEPARATOR + element.getNameTag();
}
logger.debug("Current package has changed " + currentPackage);
} else if (elementIdMap.get(element.getXmiId()) != null) {
elementIdMap.get(element.getXmiId()).setPackageContainer(currentPackage);
}
for (Node child = tw.firstChild();
child != null;
child = tw.nextSibling()) {
setPackageToElements(tw, currentPackage);
}
tw.setCurrentNode(n);
}
示例4: traverseLevel
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private static int traverseLevel(TreeWalker walker, int counter) {
// describe current node:
final Node parend = walker.getCurrentNode();
if (parend instanceof Element) {
if (((Element) parend).getAttribute("id").length() == 0) {
((Element) parend).setAttribute("id", "gen-id-" + counter);
counter++;
}
}
// traverse children:
for (Node n = walker.firstChild(); n != null; n = walker.nextSibling()) {
counter = traverseLevel(walker, counter);
}
// return position to the current (level up):
walker.setCurrentNode(parend);
return counter;
}
示例5: hasChildElement
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
public static boolean hasChildElement(TreeWalker walker)
{
Node current = walker.getCurrentNode();
Node child = walker.firstChild();
if (child != null)
{
walker.setCurrentNode(current);
return true;
}
return false;
}
示例6: fillElementIdMap
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private void fillElementIdMap(TreeWalker tw) {
Node n = tw.getCurrentNode();
Element element = (Element) n;
if (element.getAttributeNode(XmiTags.XMI_ID_TAG) != null) {
XmiElement xmiElement = new XmiElement(element, this);
elementIdMap.put(xmiElement.getXmiId(), xmiElement);
//System.out.println("entity "+xmiElement.getNameTag()+" type "+xmiElement.getXmiType());
}
for (Node child = tw.firstChild();
child != null;
child = tw.nextSibling()) {
fillElementIdMap(tw);
}
tw.setCurrentNode(n);
}
示例7: getArticleTextMapping
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
protected void getArticleTextMapping(TreeWalker walker, List<MappingNode> map) throws DOMException {
final Node parend = walker.getCurrentNode();
if (parend.getNodeType() == Node.TEXT_NODE && parend.getParentNode().getAttributes().getNamedItem("id") != null)
{
if (parend.getTextContent().trim().length() > 0)
{
final int index = findChildNodeIndex(parend.getParentNode(), parend);
if (index != -1)
{
// square brackets are not valid XML/HTML identifier
// characters, so we can use them here
map.add(new MappingNode(
parend.getParentNode().getAttributes().getNamedItem("id").getNodeValue() + "[" + index + "]",
parend.getNodeValue()));
// System.out.println(
// "ELEMENT '"+parend.getParentNode().getAttributes().getNamedItem("id").getNodeValue()
// + "["+index+"]"+"'");
// System.out.println( "VALUE: '"+parend.getNodeValue()+"'"
// );
}
}
}
// traverse children:
for (Node n = walker.firstChild(); n != null; n = walker.nextSibling()) {
getArticleTextMapping(walker, map);
}
// return position to the current (level up):
walker.setCurrentNode(parend);
}
示例8: firstChildElement
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
public static Element firstChildElement(TreeWalker walker,boolean mustExist)
{
Element childNode = (Element)walker.firstChild();
checkElement(childNode,walker, mustExist, "child");
return childNode;
}