com.jcabi.xml.XML类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(141)

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

XML介绍

[英]XML document.

Set of convenient XML manipulations:

XML xml = new XMLDocument(content); 
for (XML employee : xml.nodes("//Employee")) { 
String name = employee.xpath("name/text()").get(0); 
// ... 
}

You can always get DOM node out of this abstraction using #node()method.

toString() must produce a full XML.

Implementation of this interface must be immutable and thread-safe.
[中]XML文档。
一组方便的XML操作:

XML xml = new XMLDocument(content); 
for (XML employee : xml.nodes("//Employee")) { 
String name = employee.xpath("name/text()").get(0); 
// ... 
}

可以使用#node()方法从这个抽象中提取DOM节点。
toString()必须生成完整的XML。
这个接口的实现必须是不可变的和线程安全的。

代码示例

代码示例来源:origin: com.jcabi/jcabi-xml

@Override
public List<String> xpath(final String query) {
  return this.origin.xpath(query);
}

代码示例来源:origin: yegor256/jpeek

/**
 * Add result.
 * @param dir Directory with files
 * @throws IOException If fails
 */
public void add(final Path dir) throws IOException {
  final XML index = new XMLDocument(
    dir.resolve("index.xml").toFile()
  );
  for (final XML metric : index.nodes("//metric")) {
    this.add(
      metric.xpath("@name").get(0),
      Double.parseDouble(metric.xpath("@diff").get(0))
    );
  }
}

代码示例来源:origin: com.jcabi/jcabi-xml

@Override
public Node node() {
  return this.origin.node();
}

代码示例来源:origin: com.jcabi/jcabi-xml

@Override
public List<XML> nodes(final String query) {
  return this.origin.nodes(query);
}

代码示例来源:origin: jcabi/jcabi-github

/**
   * Fetch JSON object.
   * @return JSON
   * @checkstyle MultipleStringLiteralsCheck (30 lines)
   */
  @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
  public JsonObject json() {
    final JsonObjectBuilder builder = Json.createObjectBuilder();
    for (final XML child : this.xml.nodes("* ")) {
      final Node node = child.node();
      if (child.nodes("*").isEmpty()) {
        builder.add(node.getNodeName(), node.getTextContent());
      } else if (
        !child.xpath("//@array").isEmpty()
          && "true".equals(child.xpath("//@array").get(0))
      ) {
        final JsonArrayBuilder bld = Json.createArrayBuilder();
        for (final XML item : child.nodes("*")) {
          bld.add(item.node().getTextContent());
        }
        builder.add(node.getNodeName(), bld.build());
      } else {
        builder.add(node.getNodeName(), new JsonNode(child).json());
      }
    }
    return builder.build();
  }
}

代码示例来源:origin: com.jcabi/jcabi-xml

@Override
public XML merge(final NamespaceContext context) {
  return this.origin.merge(context);
}

代码示例来源:origin: jcabi/jcabi-xml

@Override
public XML registerNs(final String prefix, final Object uri) {
  return this.origin.registerNs(prefix, uri);
}

代码示例来源:origin: jcabi/jcabi-xml

@Override
public List<XML> nodes(final String query) {
  return this.origin.nodes(query);
}

代码示例来源:origin: yegor256/jpeek

new org.cactoos.list.Mapped<>(
    Double::parseDouble,
    xml.xpath("//class[@element='true' and @value!='NaN']/@value")
final double green = (double) xml.nodes(
  "//*[@element='true' and @color='green']"
).size();
final double yellow = (double) xml.nodes(
  "//*[@element='true' and @color='yellow']"
).size();
final double red = (double) xml.nodes(
  "//*[@element='true' and @color='red']"
).size();
  .add("xml").set(String.format("%s.xml", name)).up()
  .add("elements").set(values.size()).up()
  .add("classes").set(xml.nodes("//class").size()).up()
  .add("green").set((int) green).up()
  .add("yellow").set((int) yellow).up()
  .set(
    Boolean.toString(
      Double.parseDouble(xml.xpath("/metric/colors/@high").get(0))
      > Double.parseDouble(
        xml.xpath("/metric/colors/@low").get(0)
final Iterator<XML> bars = xml.nodes("/metric/bars").iterator();
if (bars.hasNext()) {
  dirs.add("bars").append(Directives.copyOf(bars.next().node())).up();

代码示例来源:origin: jcabi/jcabi-xml

@Override
public XML merge(final NamespaceContext context) {
  return this.origin.merge(context);
}

代码示例来源:origin: com.jcabi/jcabi-xml

@Override
public XML registerNs(final String prefix, final Object uri) {
  return this.origin.registerNs(prefix, uri);
}

代码示例来源:origin: jcabi/jcabi-xml

@Override
public List<String> xpath(final String query) {
  return this.origin.xpath(query);
}

代码示例来源:origin: com.rempl/rempl

@Override
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public Model load(final InputStream input) throws IOException {
  final XML xml = new XMLDocument(input);
  final Collection<Instance> insts = new LinkedList<Instance>();
  for (final XML node : xml.nodes("/*/instance")) {
    final ImmutableMap.Builder<String, String> attrs =
      new ImmutableMap.Builder<String, String>();
    for (final XML slot : node.nodes("slots/slot")) {
      attrs.put(
        slot.xpath("key/text()").get(0),
        slot.xpath("value/text()").get(0)
      );
    }
    insts.add(
      new Instance.Simple(
        node.xpath("name/text()").get(0),
        node.xpath("type/text()").get(0),
        attrs.build()
      )
    );
  }
  return new SimpleModel(insts);
}

代码示例来源:origin: yegor256/jpeek

@Override
public List<XML> nodes(final String query) {
  return this.output.value().nodes(query);
}

代码示例来源:origin: yegor256/jpeek

final Collection<Double> values = new Mapped<>(
  Double::parseDouble,
  xml.xpath(
      .xpath("/metric")
      .add("statistics")
      .add("total").set(xml.nodes("//class").size())
      .up()
      .add("elements").set((long) total).up()
      .add("defects")
      .set(Double.toString(defects / total)).up()
  ).applyQuietly(xml.node())
);

代码示例来源:origin: jcabi/jcabi-xml

@Override
public Node node() {
  return this.origin.node();
}

代码示例来源:origin: yegor256/jpeek

@Override
public XML merge(final NamespaceContext context) {
  return this.output.value().merge(context);
}

代码示例来源:origin: yegor256/jpeek

@Override
public XML registerNs(final String prefix, final Object uri) {
  return this.output.value().registerNs(prefix, uri);
}

代码示例来源:origin: yegor256/netbout

@Override
  public String author() {
    return xml.xpath("author/text()").get(0);
  }
};

代码示例来源:origin: yegor256/jpeek

/**
 * Add result.
 * @param dir Directory with files
 * @throws IOException If fails
 */
public void add(final Path dir) throws IOException {
  final XML index = new XMLDocument(
    dir.resolve("index.xml").toFile()
  );
  final double defects = Double.parseDouble(
    index.xpath("/index/@defects").get(0)
  );
  final int classes = Integer.parseInt(
    index.xpath("/index/metric[1]/classes/text()").get(0)
  );
  // @checkstyle MagicNumber (1 line)
  if (defects < 0.15d && classes > 200) {
    for (final XML metric : index.nodes("//metric")) {
      this.add(metric);
    }
  }
}

相关文章