nu.xom.Node.query()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中nu.xom.Node.query()方法的一些代码示例,展示了Node.query()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.query()方法的具体详情如下:
包路径:nu.xom.Node
类名称:Node
方法名:query

Node.query介绍

暂无

代码示例

代码示例来源:origin: org.xml-cml/cmlxom

public static List<CMLMolecule> extractTopLevelMolecules(Node node) {
  String xpath = "//*[not(local-name()='molecule')]" +
      "/*[local-name()='molecule'] | self::*[local-name()='molecule']";
  return CMLUtil.convertNodesToMoleculeList(node.query(xpath));
}

代码示例来源:origin: org.xml-cml/cmlxom

/**
 * convenience routine to get query nodes (iterating through get(i) is
 * fragile if nodes are removed)
 * 
 * @param node
 * @param xpath
 * @return list of nodes (immutable) - empty if none or null node
 */
public static List<Node> getQueryNodes(Node node, String xpath) {
  List<Node> nodeList = new ArrayList<Node>();
  if (node != null) {
    Nodes nodes = node.query(xpath);
    for (int i = 0; i < nodes.size(); i++) {
      nodeList.add(nodes.get(i));
    }
  }
  return nodeList;
}

代码示例来源:origin: org.xml-cml/cmlxom

/**
 * convenience routine to get query nodes (iterating thorugh get(i) is
 * fragile if nodes are removed)
 * 
 * @param node
 *            (can be null)
 * @param xpath
 *            xpath relative to node
 * @param context
 * @return list of nodes (immutable) - empty if none
 */
public static List<Node> getQueryNodes(Node node, String xpath,
    XPathContext context) {
  List<Node> nodeList = new ArrayList<Node>();
  if (node != null) {
    Nodes nodes = node.query(xpath, context);
    for (int i = 0; i < nodes.size(); i++) {
      nodeList.add(nodes.get(i));
    }
  }
  return nodeList;
}

代码示例来源:origin: org.openbase/jul.extension.xml

public static Nodes extractNodesByXpath(final String xpath, final Node node, final int expectedNumberOfNodes, final boolean throwException) throws XMLParsingException {
  Nodes nodes = node.query(xpath);
  if (nodes.size() == expectedNumberOfNodes) {
    return nodes;
  }
  if (throwException) {
    throw new XMLParsingException("Expected " + expectedNumberOfNodes + " to be found with xPath " + xpath + ", found " + nodes.size());
  }
  return nodes;
}

代码示例来源:origin: org.openbase/jul.extension.xml

public static Nodes extractNodesByXpath(final String xpath, final Node node, final NumberOfNodes expectedNumberOfNodes) throws MissingNodeException, OverissueNodeException, NotOneNodeException {
  Nodes nodes = node.query(xpath);
  switch (expectedNumberOfNodes) {
    case ARBITRARY: {
      break;
    }
    case AT_LEAST_ONE: {
      if (nodes.size() < 1) {
        throw new MissingNodeException(xpath, node);
      }
      break;
    }
    case AT_MOST_ONE: {
      if (nodes.size() > 1) {
        throw new OverissueNodeException(xpath, nodes, node);
      }
      break;
    }
    case EXACT_ONE: {
      if (nodes.size() != 1) {
        throw new NotOneNodeException(xpath, nodes, node);
      }
      break;
    }
    default:
      throw new AssertionError("Found not handled value[" + expectedNumberOfNodes.name() + "]!");
  }
  return nodes;
}

代码示例来源:origin: org.openbase/jul.extension.xml

/**
 * <p>
 * Returns the first Attribute with name attrName from Document doc. Uses xPath "//
 *
 * @throws org.openbase.jul.extension.xml.exception.XMLParsingException
 * @param throwException flag set throw exception if no such Attribute can be found.    <br>
 * @param attrName
 * @param doc
 * @return
 */
public static String extractAttributeValue(final String attrName, final Node doc, final boolean throwException) throws XMLParsingException {
  String xpath = "descendant-or-self::*/@" + attrName;
  Nodes nodes = doc.query(xpath);
  for (int i = 0; i < nodes.size(); i++) {
    if (nodes.get(i) instanceof Attribute) {
      return nodes.get(i).getValue();
    }
  }
  if (throwException) {
    throw new XMLParsingException("No Attribute " + attrName + " in document:\n" + doc.toXML());
  } else {
    return null;
  }
}

代码示例来源:origin: org.specrunner/specrunner-sql

schema.setName(nSchema.getAttribute(ATTR_NAME)).setAlias(nSchema.getAttribute(ATTR_ALIAS, schema.getName()));
Nodes nTables = nSchema.getNode().query("child::table");
for (int i = 0; i < nTables.size(); i++) {
  INodeHolder nTable = holderFactory.newHolder(nTables.get(i));
  schema.add(table);
  Nodes nColumns = nTable.getNode().query("child::column");
  for (int j = 0; j < nColumns.size(); j++) {
    INodeHolder nColumn = holderFactory.newHolder(nColumns.get(j));

相关文章