org.w3c.dom.Element.getFirstChild()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(198)

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

Element.getFirstChild介绍

暂无

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private Element findFirstChildElement(Element parent) {
  Node ret = parent.getFirstChild();
  while (ret != null && (!(ret instanceof Element))) {
    ret = ret.getNextSibling();
  }
  return (Element) ret;
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private Element findChildElement(Element parent, String name) {
  if (parent == null) {
    return null;
  }
  Node ret = parent.getFirstChild();
  while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals(name))) {
    ret = ret.getNextSibling();
  }
  return (Element) ret;
}

代码示例来源:origin: DozerMapper/dozer

public String getNodeValue(Element element) {
    Node child = element.getFirstChild();
    if (child == null) {
      return "";
    }
    String nodeValue = child.getNodeValue();
    if (nodeValue != null) {
      return nodeValue.trim();
    } else {
      return "";
    }
  }
}

代码示例来源:origin: geoserver/geoserver

/**
 * getChildElement purpose.
 *
 * <p>Used to help with XML manipulations. Returns the first child element of the specified
 * name. An exception occurs when the node is required and not found.
 *
 * @param root The root element to look for children in.
 * @param name The name of the child element to look for.
 * @param mandatory true when an exception should be thrown if the child element does not exist.
 * @return The child element found, null if not found.
 * @throws Exception When a child element is required and not found.
 */
public static Element getChildElement(Element root, String name, boolean mandatory)
    throws Exception {
  Node child = root.getFirstChild();
  while (child != null) {
    if (child.getNodeType() == Node.ELEMENT_NODE) {
      if (name.equals(child.getNodeName())) {
        return (Element) child;
      }
    }
    child = child.getNextSibling();
  }
  if (mandatory && (child == null)) {
    throw new Exception(
        root.getNodeName() + " does not contains a child element named " + name);
  }
  return null;
}

代码示例来源:origin: jamesagnew/hapi-fhir

Property property = getTextProp(properties);
  if (property != null) {
   context.getChildren().add(new Element(property.getName(), property, property.getType(), text).markLocation(line(node), col(node)));
  } else {
  logError(line(node), col(node), path, IssueType.STRUCTURE, "Text should not be present", IssueSeverity.ERROR);
    ok = ok || (attr.getLocalName().equals("schemaLocation")); // xsi:schemalocation allowed for non FHIR content
   ok = ok || (hasTypeAttr(context) && attr.getLocalName().equals("type") && FormatUtilities.NS_XSI.equals(attr.getNamespaceURI())); // xsi:type allowed if element says so
Node child = node.getFirstChild();
while (child != null) {
  if (child.getNodeType() == Node.ELEMENT_NODE) {
     else 
     xhtml = new XhtmlParser().setValidatorMode(true).parseHtmlNode((org.w3c.dom.Element) child);
          context.getChildren().add(new Element(property.getName(), property, "xhtml", new XhtmlComposer(XhtmlComposer.XML, false).compose(xhtml)).setXhtml(xhtml).markLocation(line(child), col(child)));
  } else if (child.getNodeType() == Node.CDATA_SECTION_NODE){
  logError(line(child), col(child), path, IssueType.STRUCTURE, "CDATA is not allowed", IssueSeverity.ERROR);      		
  } else if (!Utilities.existsInList(child.getNodeType(), 3, 8)) {
  child = child.getNextSibling();

代码示例来源:origin: geoserver/geoserver

List styles = new ArrayList();
while ((j = baseMapStyles.indexOf(',', k)) != -1) {
  styles.add(baseMapStyles.substring(k, j).trim());
  k = j + 1;
  styles.add("");
} else if (k < baseMapStyles.length() - 1) {
  styles.add(baseMapStyles.substring(k).trim());
double x1 =
    Double.parseDouble(
        posElements[0].getFirstChild().getNodeValue().split(" ")[0]);
double y1 =
    Double.parseDouble(
        posElements[0].getFirstChild().getNodeValue().split(" ")[1]);
double x2 =
    Double.parseDouble(
        posElements[1].getFirstChild().getNodeValue().split(" ")[0]);
double y2 =
    Double.parseDouble(
        posElements[1].getFirstChild().getNodeValue().split(" ")[1]);

代码示例来源:origin: jamesagnew/hapi-fhir

private XhtmlNode parseNode(Element node, String defaultNS) throws FHIRFormatError  {
 XhtmlNode res = new XhtmlNode(NodeType.Element);
 res.setName(node.getLocalName());
 defaultNS = checkNS(res, node, defaultNS);
 for (int i = 0; i < node.getAttributes().getLength(); i++) {
  Attr attr = (Attr) node.getAttributes().item(i);
  if (attributeIsOk(res.getName(), attr.getName(), attr.getValue()) && !attr.getLocalName().startsWith("xmlns"))
   res.getAttributes().put(attr.getName(), attr.getValue());
 }
 Node child = node.getFirstChild();
 while (child != null) {
  if (child.getNodeType() == Node.TEXT_NODE) {
   res.addText(child.getTextContent());
  } else if (child.getNodeType() == Node.COMMENT_NODE) {
   res.addComment(child.getTextContent());
  } else if (child.getNodeType() == Node.ELEMENT_NODE) {
   if (elementIsOk(child.getLocalName()))
    res.getChildNodes().add(parseNode((Element) child, defaultNS));
  } else
   throw new FHIRFormatError("Unhandled XHTML feature: "+Integer.toString(child.getNodeType())+descLoc());
  child = child.getNextSibling();
 }
 return res;
}

代码示例来源:origin: babyfish-ct/babyfish

private static List<Element> getChildElements(Element element, String childElementName) {
  List<Element> elements = new ArrayList<>();
  for (Node childNode = element.getFirstChild(); 
      childNode != null;
      childNode = childNode.getNextSibling()) {
    if (childNode instanceof Element && childNode.getLocalName().equals(childElementName)) {
      elements.add((Element)childNode);
    }
  }
  return elements;
}

代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http

BeanDefinitionBuilder bean
) {
  Node n = parent.getFirstChild();
  while (n != null) {
    if (Node.ELEMENT_NODE != n.getNodeType()
      || !HTTP_NS.equals(n.getNamespaceURI())) {
      n = n.getNextSibling();
      continue;
    String elementName = n.getLocalName();
      mapTLSClientParameters((Element)n, bean);
    n = n.getNextSibling();

代码示例来源:origin: Tencent/tinker

public static void processValuesFile(String valuesFullFilename, AaptResourceCollector resourceCollector) throws Exception {
  Document document = JavaXmlUtil.parse(valuesFullFilename);
  String directoryName = new File(valuesFullFilename).getParentFile().getName();
  Element root = document.getDocumentElement();
  for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) {
    if (node.getNodeType() != Node.ELEMENT_NODE) {
      continue;
    String resourceType = node.getNodeName();
    if (resourceType.equals(ITEM_TAG)) {
      resourceType = node.getAttributes().getNamedItem("type").getNodeValue();
      if (resourceType.equals("id")) {
        resourceCollector.addIgnoreId(node.getAttributes().getNamedItem("name").getNodeValue());

代码示例来源:origin: geotools/geotools

public void testEncode() throws Exception {
    FunctionName function = FilterMockData.functionName();
    Document dom =
        encode(function, new QName(OGC.NAMESPACE, "Function"), OGC.Function_NameType);

    assertEquals("foo", dom.getDocumentElement().getFirstChild().getNodeValue());
    assertEquals("2", dom.getDocumentElement().getAttribute("nArgs"));
  }
}

代码示例来源:origin: geotools/geotools

public void testEncodeWithCRS() throws Exception {
  Envelope e = new ReferencedEnvelope(-180, -90, 180, 90, CRS.decode("EPSG:4326"));
  Document dom = encode(e, GML.boundedBy);
  assertEquals("gml:Envelope", dom.getDocumentElement().getFirstChild().getNodeName());
  assertTrue(
      ((Element) dom.getDocumentElement().getFirstChild())
          .getAttribute("srsName")
          .endsWith("4326"));
}

代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http

Node n = e.getFirstChild();
while (n != null) {
  if (Node.ELEMENT_NODE != n.getNodeType()
    || !SECURITY_NS.equals(n.getNamespaceURI())) {
    n = n.getNextSibling();
    continue;
  String ename = n.getLocalName();
  String ref = ((Element)n).getAttribute("ref");
    paramsbean.addPropertyValue(ename, n.getTextContent());
  n = n.getNextSibling();

代码示例来源:origin: apache/geode

private Document mangleWebXml(final Document doc) {
 final Element docElement = doc.getDocumentElement();
 final NodeList nodelist = docElement.getChildNodes();
 Node firstFilter = null;
  final String name = node.getNodeName();
  if ("display-name".equals(name)) {
   displayElement = node;
  first = docElement.getFirstChild();

代码示例来源:origin: ehcache/ehcache3

private ClusteringCacheManagerServiceConfigurationParser.ServerSideConfig processServerSideConfig(Node serverSideConfigElement) {
 ClusteringCacheManagerServiceConfigurationParser.ServerSideConfig serverSideConfig = new ClusteringCacheManagerServiceConfigurationParser.ServerSideConfig();
 serverSideConfig.autoCreate = Boolean.parseBoolean(((Element)serverSideConfigElement).getAttribute("auto-create"));
 final NodeList serverSideNodes = serverSideConfigElement.getChildNodes();
 for (int i = 0; i < serverSideNodes.getLength(); i++) {
  final Node item = serverSideNodes.item(i);
  if (Node.ELEMENT_NODE == item.getNodeType()) {
   String nodeLocalName = item.getLocalName();
   if ("default-resource".equals(nodeLocalName)) {
    serverSideConfig.defaultServerResource = ((Element)item).getAttribute("from");
    String poolName = sharedPoolElement.getAttribute("name");     // required
    Attr fromAttr = sharedPoolElement.getAttributeNode("from");   // optional
    String fromResource = (fromAttr == null ? null : fromAttr.getValue());
    MemoryUnit memoryUnit = MemoryUnit.valueOf(unit.toUpperCase(Locale.ENGLISH));
    String quantityValue = sharedPoolElement.getFirstChild().getNodeValue();
    long quantity;
    try {

代码示例来源:origin: jamesagnew/hapi-fhir

private void readXml() throws FHIRException  {
 Element root = xml.getDocumentElement();
 check(root.getNamespaceURI().equals(XLS_NS), "Spreadsheet namespace incorrect");
 check(root.getNodeName().equals("Workbook"), "Spreadsheet element name incorrect");
 Node node = root.getFirstChild();
 while (node != null) {
  if (node.getNodeName().equals("Worksheet"))
   processWorksheet((Element)node);
  node = node.getNextSibling();
 }
}

代码示例来源:origin: marytts/marytts

/**
 * Get the first child of <code>e</code> which is an element, or <code>null</code> if there is no such element.
 * 
 * @param e
 *            e
 * @return n
 */
public static Element getFirstChildElement(Element e) {
  Node n = e.getFirstChild();
  while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
    n = n.getNextSibling();
  }
  // Now n is either null or an Element
  return (Element) n;
}

代码示例来源:origin: plutext/docx4j

void convertToNodes() throws CanonicalizationException, 
  ParserConfigurationException, IOException, SAXException {
  DocumentBuilder db = XMLUtils.createDocumentBuilder(false, secureValidation);
  // select all nodes, also the comments.        
  try {
    db.setErrorHandler(new org.docx4j.org.apache.xml.security.utils.IgnoreAllErrorHandler());
    Document doc = db.parse(this.getOctetStream());
    this.subNode = doc;
  } catch (SAXException ex) {
    // if a not-wellformed nodeset exists, put a container around it...
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write("<container>".getBytes("UTF-8"));
    baos.write(this.getBytes());
    baos.write("</container>".getBytes("UTF-8"));
    byte result[] = baos.toByteArray();
    Document document = db.parse(new ByteArrayInputStream(result));
    this.subNode = document.getDocumentElement().getFirstChild().getFirstChild();
  } finally {
    XMLUtils.repoolDocumentBuilder(db);
    if (this.inputOctetStreamProxy != null) {
      this.inputOctetStreamProxy.close();
    }
    this.inputOctetStreamProxy = null;
    this.bytes = null;
  }
}

代码示例来源:origin: geotools/geotools

public void testEncode() throws Exception {
    Literal literal = FilterMockData.literal();
    Document dom = encode(literal, OGC.Literal);

    assertEquals("foo", dom.getDocumentElement().getFirstChild().getNodeValue());
  }
}

代码示例来源:origin: xalan/xalan

Node n = elem.getFirstChild();
 if (n.getNodeType() == Node.ELEMENT_NODE)
  else TypeStr = Type.getNodeValue();
   String value = n1.getNodeValue();
   if (value == null) value = "";
} while ( (n = n.getNextSibling()) != null);

相关文章

微信公众号

最新文章

更多