Codota Logo
Node.getFirstChild
Code IndexAdd Codota to your IDE (free)

How to use
getFirstChild
method
in
org.w3c.dom.Node

Best Java code snippets using org.w3c.dom.Node.getFirstChild (Showing top 20 results out of 7,488)

Refine searchRefine arrow

  • Node.getNextSibling
  • Node.getNodeType
  • Node.getNodeValue
  • NodeList.item
  • NodeList.getLength
  • Node.getNodeName
  • Common ways to obtain Node
private void myMethod () {
Node n =
  • Codota IconNodeList children;children.item(index)
  • Codota IconElement element;element.getFirstChild()
  • Codota IconNamedNodeMap attributes;String name;attributes.getNamedItem(name)
  • Smart code suggestions by Codota
}
origin: stackoverflow.com

 String url = "http://stackoverflow.com/questions/3152138";
Document document = new Tidy().parseDOM(new URL(url).openStream(), null);
XPath xpath = XPathFactory.newInstance().newXPath();

Node question = (Node) xpath.compile("//*[@id='question']//*[contains(@class,'post-text')]//p[1]").evaluate(document, XPathConstants.NODE);
System.out.println("Question: " + question.getFirstChild().getNodeValue());

NodeList answerers = (NodeList) xpath.compile("//*[@id='answers']//*[contains(@class,'user-details')]//a[1]").evaluate(document, XPathConstants.NODESET);
for (int i = 0; i < answerers.getLength(); i++) {
  System.out.println("Answerer: " + answerers.item(i).getFirstChild().getNodeValue());
}
origin: AsyncHttpClient/async-http-client

private void parse(Document document) {
 Element element = document.getDocumentElement();
 NodeList statusNode = element.getElementsByTagName("status");
 for (int i = 0; i < statusNode.getLength(); i++) {
  Node node = statusNode.item(i);
  String value = node.getFirstChild().getNodeValue();
  int statusCode = Integer.valueOf(value.substring(value.indexOf(" "), value.lastIndexOf(" ")).trim());
  String statusText = value.substring(value.lastIndexOf(" "));
  status = new HttpStatusWrapper(status, statusText, statusCode);
 }
}
origin: oracle/opengrok

private String getValue(Node node) {
  if (node == null) {
    return null;
  }
  StringBuilder sb = new StringBuilder();
  Node n = node.getFirstChild();
  while (n != null) {
    if (n.getNodeType() == Node.TEXT_NODE) {
      sb.append(n.getNodeValue());
    }
    n = n.getNextSibling();
  }
  return sb.toString();
}
origin: org.freemarker/freemarker

/**
 * Recursively removes all comment nodes from the subtree.
 *
 * @see #simplify
 */
static public void removeComments(Node parent) {
  Node child = parent.getFirstChild();
  while (child != null) {
    Node nextSibling = child.getNextSibling();
    if (child.getNodeType() == Node.COMMENT_NODE) {
      parent.removeChild(child);
    } else if (child.hasChildNodes()) {
      removeComments(child);
    }
    child = nextSibling;
  }
}
 
origin: kiegroup/jbpm

protected void readDataInputAssociation(org.w3c.dom.Node xmlNode, Map<String, String> forEachNodeInputAssociation) {
  // sourceRef
  org.w3c.dom.Node subNode = xmlNode.getFirstChild();
  if ("sourceRef".equals(subNode.getNodeName())) {
    String source = subNode.getTextContent();
    // targetRef
    subNode = subNode.getNextSibling();
    String target = subNode.getTextContent();
    forEachNodeInputAssociation.put(target, source);
  }
}
origin: pmd/pmd

String entityName = item.getNodeName();
Node firstChild = item.getFirstChild();
if (firstChild != null) {
  result = result.replaceAll(Matcher.quoteReplacement(firstChild.getNodeValue()),
      "&" + entityName + ";");
} else {
origin: yaphone/itchat4j

if (doc != null) {
  core.getLoginInfo().put(StorageLoginInfoEnum.skey.getKey(),
      doc.getElementsByTagName(StorageLoginInfoEnum.skey.getKey()).item(0).getFirstChild()
          .getNodeValue());
  core.getLoginInfo().put(StorageLoginInfoEnum.wxsid.getKey(),
      doc.getElementsByTagName(StorageLoginInfoEnum.wxsid.getKey()).item(0).getFirstChild()
          .getNodeValue());
  core.getLoginInfo().put(StorageLoginInfoEnum.wxuin.getKey(),
      doc.getElementsByTagName(StorageLoginInfoEnum.wxuin.getKey()).item(0).getFirstChild()
          .getNodeValue());
  core.getLoginInfo().put(StorageLoginInfoEnum.pass_ticket.getKey(),
      doc.getElementsByTagName(StorageLoginInfoEnum.pass_ticket.getKey()).item(0).getFirstChild()
          .getNodeValue());
origin: plantuml/plantuml

private String displayMetadata(Node node, int level) {
  final NamedNodeMap map = node.getAttributes();
  if (map != null) {
    final Node keyword = map.getNamedItem("keyword");
    if (keyword != null && tag.equals(keyword.getNodeValue())) {
      final Node text = map.getNamedItem("value");
      if (text != null) {
        return text.getNodeValue();
      }
    }
  }
  Node child = node.getFirstChild();
  // children, so close current tag
  while (child != null) {
    // print children recursively
    final String result = displayMetadata(child, level + 1);
    if (result != null) {
      return result;
    }
    child = child.getNextSibling();
  }
  return null;
}
origin: stanfordnlp/CoreNLP

private static AceCharSeq parseCharSeq(Node node) {
 Node child = getChildByName(node, "charseq");
 String start = getAttributeValue(child, "START");
 String end = getAttributeValue(child, "END");
 String text = child.getFirstChild().getNodeValue();
 return new AceCharSeq(text,
      Integer.parseInt(start),
      Integer.parseInt(end));
}
origin: kiegroup/jbpm

public void executeWorkItem(WorkItem workItem,
    WorkItemManager mgr) {
  assertEquals("id", ((org.w3c.dom.Node) workItem
      .getParameter("coId")).getNodeName());
  assertEquals("some text", ((org.w3c.dom.Node) workItem
      .getParameter("coId")).getFirstChild()
      .getTextContent());
}
origin: groovy/groovy-core

protected void printChildren(Node parent, Map namespaces) {
  for (Node node = parent.getFirstChild(); node != null; node = node.getNextSibling()) {
    print(node, namespaces, false);
  }
}
origin: pentaho/pentaho-kettle

public String getSample( String strFunctionName, String strFunctionNameWithArgs ) {
 String sRC = "// Sorry, no Script available for " + strFunctionNameWithArgs;
 NodeList nl = dom.getElementsByTagName( "jsFunction" );
 for ( int i = 0; i < nl.getLength(); i++ ) {
  if ( nl.item( i ).getAttributes().getNamedItem( "name" ).getNodeValue().equals( strFunctionName ) ) {
   Node elSample = ( (Element) nl.item( i ) ).getElementsByTagName( "sample" ).item( 0 );
   if ( elSample.hasChildNodes() ) {
    return ( elSample.getFirstChild().getNodeValue() );
   }
  }
 }
 return sRC;
}
origin: plutext/docx4j

/**
 * Method getStrFromNode
 *
 * @param xpathnode
 * @return the string for the node.
 */
public static String getStrFromNode(Node xpathnode) {
  if (xpathnode.getNodeType() == Node.TEXT_NODE) {
    // we iterate over all siblings of the context node because eventually,
    // the text is "polluted" with pi's or comments
    StringBuilder sb = new StringBuilder();
    for (Node currentSibling = xpathnode.getParentNode().getFirstChild();
      currentSibling != null;
      currentSibling = currentSibling.getNextSibling()) {
      if (currentSibling.getNodeType() == Node.TEXT_NODE) {
        sb.append(((Text) currentSibling).getData());
      }
    }
    return sb.toString();
  } else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
    return xpathnode.getNodeValue();
  } else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
    return xpathnode.getNodeValue();
  }
  return null;
}
origin: spullara/mustache.java

private Object get(Node de) {
 if (!de.hasChildNodes()) {
  return "";
 } else if (de.getChildNodes().getLength() == 1 && de.getFirstChild() instanceof Text) {
  return de.getTextContent();
 } else {
  NodeList childNodes = de.getChildNodes();
  Map<String, Object> map = new HashMap<>();
  for (int i = 0; i < childNodes.getLength(); i++) {
   Node item = childNodes.item(i);
   if (!(item instanceof Text)) {
    put(item, map);
   }
  }
  return map;
 }
}
origin: org.freemarker/freemarker

/**
 * Recursively removes all processing instruction nodes from the subtree.
 *
 * @see #simplify
 */
static public void removePIs(Node parent) {
  Node child = parent.getFirstChild();
  while (child != null) {
    Node nextSibling = child.getNextSibling();
    if (child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
      parent.removeChild(child);
    } else if (child.hasChildNodes()) {
      removePIs(child);
    }
    child = nextSibling;
  }
}
 
origin: kiegroup/jbpm

protected void readDataOutputAssociation(org.w3c.dom.Node xmlNode, Map<String, String> forEachNodeOutputAssociation) {
  // sourceRef
  org.w3c.dom.Node subNode = xmlNode.getFirstChild();
  if ("sourceRef".equals(subNode.getNodeName())) {
    String source = subNode.getTextContent();
    // targetRef
    subNode = subNode.getNextSibling();
    String target = subNode.getTextContent();
    forEachNodeOutputAssociation.put(source, target);
  }
}
origin: kiegroup/jbpm

public void executeWorkItem(WorkItem workItem,
    WorkItemManager mgr) {
  Object coIdParamObj = workItem.getParameter("coId");
  assertEquals("mydoc", ((Element) coIdParamObj).getNodeName());
  assertEquals("mynode", ((Element) workItem.getParameter("coId")).getFirstChild().getNodeName());
  assertEquals("user",
      ((Element) workItem.getParameter("coId"))
          .getFirstChild().getFirstChild()
          .getNodeName());
  assertEquals("hello world",
      ((Element) workItem.getParameter("coId"))
          .getFirstChild().getFirstChild()
          .getAttributes().getNamedItem("hello")
          .getNodeValue());
}
origin: ehcache/ehcache3

@Test
public void testDefaulSerializerXmlsSerializersValueHasWhitespaces() throws Exception {
 final URL resource = XmlConfigurationTest.class.getResource("/configs/default-serializer.xml");
 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
 Document doc = dBuilder.parse(new File(resource.toURI()));
 NodeList nList = doc.getElementsByTagName("ehcache:serializer");
 assertThat(nList.item(2).getFirstChild().getNodeValue(), containsString(" "));
 assertThat(nList.item(2).getFirstChild().getNodeValue(), containsString("\n"));
 assertThat(nList.item(3).getFirstChild().getNodeValue(), containsString(" "));
 assertThat(nList.item(3).getFirstChild().getNodeValue(), containsString("\n"));
 nList = doc.getElementsByTagName("ehcache:key-type");
 assertThat(nList.item(0).getFirstChild().getNodeValue(), containsString(" "));
 assertThat(nList.item(0).getFirstChild().getNodeValue(), containsString("\n"));
 assertThat(nList.item(1).getFirstChild().getNodeValue(), containsString(" "));
 assertThat(nList.item(1).getFirstChild().getNodeValue(), containsString("\n"));
 nList = doc.getElementsByTagName("ehcache:value-type");
 assertThat(nList.item(0).getFirstChild().getNodeValue(), containsString(" "));
 assertThat(nList.item(0).getFirstChild().getNodeValue(), containsString("\n"));
 assertThat(nList.item(1).getFirstChild().getNodeValue(), containsString(" "));
 assertThat(nList.item(1).getFirstChild().getNodeValue(), containsString("\n"));
}
origin: org.apache.poi/poi-ooxml

private String getComplexTypeNameFromChildren(Node localComplexTypeRootNode,
    String elementNameWithoutNamespace) {
  if(localComplexTypeRootNode == null) {
    return "";
  }
  Node node  = localComplexTypeRootNode.getFirstChild();
  String complexTypeName = "";
  while (node != null) {
    if ( node instanceof Element && "element".equals(node.getLocalName())) {
      Node nameAttribute = getNameOrRefElement(node);
      if (nameAttribute.getNodeValue().equals(elementNameWithoutNamespace)) {
        Node complexTypeAttribute = node.getAttributes().getNamedItem("type");
        if (complexTypeAttribute!=null) {
          complexTypeName = complexTypeAttribute.getNodeValue();
          break;
        }
      }
    }
    node = node.getNextSibling();
  }
  return complexTypeName;
}
origin: real-logic/simple-binary-encoding

/**
 * Construct a ValidValue given the XML node and the encodingType.
 *
 * @param node         that contains the validValue
 * @param encodingType for the enum
 */
public ValidValue(final Node node, final PrimitiveType encodingType)
{
  name = getAttributeValue(node, "name");
  description = getAttributeValueOrNull(node, "description");
  value = PrimitiveValue.parse(node.getFirstChild().getNodeValue(), encodingType);
  sinceVersion = Integer.parseInt(getAttributeValue(node, "sinceVersion", "0"));
  deprecated = Integer.parseInt(getAttributeValue(node, "deprecated", "0"));
  checkForValidName(node, name);
}
org.w3c.domNodegetFirstChild

Javadoc

The first child of this node. If there is no such node, this returns null.

Popular methods of Node

  • getNodeName
    The name of this node, depending on its type; see the table above.
  • getNodeValue
    The value of this node, depending on its type; see the table above. When it is defined to be null, s
  • getNodeType
    A code representing the type of the underlying object, as defined above.
  • getChildNodes
    A NodeList that contains all children of this node. If there are no children, this is a NodeList con
  • getTextContent
    This attribute returns the text content of this node and its descendants. When it is defined to be n
  • getAttributes
    A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
  • getLocalName
    Returns the local part of the qualified name of this node. For nodes of any type other than ELEMENT_
  • getParentNode
    The parent of this node. All nodes, except Attr,Document, DocumentFragment, Entity, and Notation may
  • getNextSibling
    The node immediately following this node. If there is no such node, this returns null.
  • appendChild
    Adds the node newChild to the end of the list of children of this node. If the newChild is already
  • getNamespaceURI
    The namespace URI of this node, or null if it is unspecified. This is not a computed value that is t
  • getOwnerDocument
    The Document object associated with this node. This is also the Document object used to create new n
  • getNamespaceURI,
  • getOwnerDocument,
  • removeChild,
  • hasChildNodes,
  • getPrefix,
  • setNodeValue,
  • getPreviousSibling,
  • insertBefore,
  • cloneNode

Popular in Java

  • Reading from database using SQL prepared statement
  • setScale (BigDecimal)
  • addToBackStack (FragmentTransaction)
  • onRequestPermissionsResult (Fragment)
  • ResourceBundle (java.util)
    Resource bundles contain locale-specific objects. When your program needs a locale-specific resource
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.This exception may include information for locating the er
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now