本文整理汇总了Java中org.w3c.dom.Element.getFirstChild方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getFirstChild方法的具体用法?Java Element.getFirstChild怎么用?Java Element.getFirstChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Element
的用法示例。
在下文中一共展示了Element.getFirstChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseParameterArray
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Parses a parameter array and returns Vector of found subParameters
* @param parameterNode
* @return Vector with found subParameters
*/
protected static Vector<Node> parseParameterArray(Element parameterNode) {
Vector<Node> ret = new Vector<Node>();
Node child = parameterNode.getFirstChild();
while (child != null) {
while (child != null && (child.getNodeType() != Node.ELEMENT_NODE || !child.getNodeName().equals(XML_E_SUBPARAMETER))) {
child = child.getNextSibling();
}
if (child == null) {
break;
}
// Puts found subParameter into destination Vector
ret.add(child);
child = child.getNextSibling();
}
return ret;
}
示例2: matches
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public boolean matches(Element element) {
for (Node child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
short type = child.getNodeType();
if (type == Node.ELEMENT_NODE) {
return false;
} else if (type == Node.TEXT_NODE ||
type == Node.CDATA_SECTION_NODE ||
type == Node.ENTITY_REFERENCE_NODE) {
String content = child.getTextContent();
if (content != null && !content.isEmpty()) {
return false;
}
}
}
return true;
}
示例3: getFirstElementChild
import org.w3c.dom.Element; //导入方法依赖的package包/类
public static Element getFirstElementChild(Element element, String namespace,
String localname) {
ParamUtil.requireNonNull("element", element);
ParamUtil.requireNonBlank("localname", localname);
Node node = element.getFirstChild();
if (node == null) {
return null;
}
do {
if (match(node, namespace, localname)) {
return (Element) node;
}
node = node.getNextSibling();
}
while (node != null);
return null;
}
示例4: unmarshalKeyValue
import org.w3c.dom.Element; //导入方法依赖的package包/类
PublicKey unmarshalKeyValue(Element kvtElem)
throws MarshalException
{
if (rsakf == null) {
try {
rsakf = KeyFactory.getInstance("RSA");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException
("unable to create RSA KeyFactory: " + e.getMessage());
}
}
Element modulusElem = DOMUtils.getFirstChildElement(kvtElem,
"Modulus");
modulus = new DOMCryptoBinary(modulusElem.getFirstChild());
Element exponentElem = DOMUtils.getNextSiblingElement(modulusElem,
"Exponent");
exponent = new DOMCryptoBinary(exponentElem.getFirstChild());
RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus.getBigNum(),
exponent.getBigNum());
return generatePublicKey(rsakf, spec);
}
示例5: decode
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Method decode
*
* Takes the <CODE>Text</CODE> children of the Element and interprets
* them as input for the <CODE>Base64.decode()</CODE> function.
*
* @param element
* @return the byte obtained of the decoding the element
* $todo$ not tested yet
* @throws Base64DecodingException
*/
public static final byte[] decode(Element element) throws Base64DecodingException {
Node sibling = element.getFirstChild();
StringBuffer sb = new StringBuffer();
while (sibling != null) {
if (sibling.getNodeType() == Node.TEXT_NODE) {
Text t = (Text) sibling;
sb.append(t.getData());
}
sibling = sibling.getNextSibling();
}
return decode(sb.toString());
}
示例6: getNodeValue
import org.w3c.dom.Element; //导入方法依赖的package包/类
/** Return the text value of the first child of the named node, or the specified default if the node can't be found.<br>
* For example, calling getNodeValue(el, "Mode", "whatever") on a list of elements which contains the following XML:
* <Mode>survival</Mode>
* should return "survival".
* @param elements the list of XML elements to search
* @param nodeName the name of the parent node to extract the text value from
* @param defaultValue the default to return if the node is empty / doesn't exist
* @return the text content of the desired element
*/
static public String getNodeValue(List<Element> elements, String nodeName, String defaultValue)
{
if (elements != null)
{
for (Element el : elements)
{
if (el.getNodeName().equals(nodeName))
{
if (el.getFirstChild() != null)
{
return el.getFirstChild().getTextContent();
}
}
}
}
return defaultValue;
}
示例7: decode
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Method decode
*
* Takes the <CODE>Text</CODE> children of the Element and interprets
* them as input for the <CODE>Base64.decode()</CODE> function.
*
* @param element
* @return the byte obtained of the decoding the element
* $todo$ not tested yet
* @throws Base64DecodingException
*/
public static final byte[] decode(Element element) throws Base64DecodingException {
Node sibling = element.getFirstChild();
StringBuilder sb = new StringBuilder();
while (sibling != null) {
if (sibling.getNodeType() == Node.TEXT_NODE) {
Text t = (Text) sibling;
sb.append(t.getData());
}
sibling = sibling.getNextSibling();
}
return decode(sb.toString());
}
示例8: countKids
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Count number of children of a certain type of the given element.
*
* @param elem the element whose kids are to be counted
*
* @return the number of matching kids.
*/
public static int countKids (Element elem, short nodeType) {
int nkids = 0;
for (Node n = elem.getFirstChild (); n != null; n = n.getNextSibling ()) {
if (n.getNodeType () == nodeType) {
nkids++;
}
}
return nkids;
}
示例9: walkTree
import org.w3c.dom.Element; //导入方法依赖的package包/类
public static void walkTree(Element start, Consumer<Element> consumer) {
consumer.accept(start);
Node child = start.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
walkTree((Element)child, consumer);
}
child = child.getNextSibling();
}
}
示例10: loopDoorChildren
import org.w3c.dom.Element; //导入方法依赖的package包/类
private void loopDoorChildren(final Context context, final Element element, final Map<Child, Object> childValues)
throws XmlException {
Node childElement = element.getFirstChild();
while (childElement != null) {
verwerkChildElement(context, childValues, childElement);
childElement = childElement.getNextSibling();
}
}
示例11: testComments002
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: the root element has two Comment nodes, <br>
* <b>name</b>: comments <br>
* <b>value</b>: false. <br>
* <b>Expected results</b>: the root element has no children
*/
@Test
public void testComments002() {
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException pce) {
Assert.fail(pce.toString());
} catch (FactoryConfigurationError fce) {
Assert.fail(fce.toString());
}
Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);
Comment comment1 = doc.createComment("comment1");
Comment comment2 = doc.createComment("comment2");
DOMConfiguration config = doc.getDomConfig();
config.setParameter("comments", Boolean.FALSE);
Element root = doc.getDocumentElement();
root.appendChild(comment1);
root.appendChild(comment2);
doc.normalizeDocument();
if (root.getFirstChild() != null) {
Assert.fail("root has a child " + root.getFirstChild() + ", but expected to has none");
}
return; // Status.passed("OK");
}
示例12: create
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Creates a {@link Message} from an {@link Element} that represents
* the whole SOAP message.
*
* @param soapEnvelope
* The SOAP envelope element.
*/
public static Message create(Element soapEnvelope) {
SOAPVersion ver = SOAPVersion.fromNsUri(soapEnvelope.getNamespaceURI());
// find the headers
Element header = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Header");
HeaderList headers = null;
if(header!=null) {
for( Node n=header.getFirstChild(); n!=null; n=n.getNextSibling() ) {
if(n.getNodeType()==Node.ELEMENT_NODE) {
if(headers==null)
headers = new HeaderList(ver);
headers.add(Headers.create((Element)n));
}
}
}
// find the payload
Element body = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Body");
if(body==null)
throw new WebServiceException("Message doesn't have <S:Body> "+soapEnvelope);
Element payload = DOMUtil.getFirstChild(soapEnvelope, ver.nsUri, "Body");
if(payload==null) {
return new EmptyMessageImpl(headers, new AttachmentSetImpl(), ver);
} else {
return new DOMMessage(ver,headers,payload);
}
}
示例13: write
import org.w3c.dom.Element; //导入方法依赖的package包/类
protected void write(Element node) throws ShellException {
printWriter.print('<');
printWriter.print(node.getNodeName());
Attr attrs[] = sortAttributes(node.getAttributes());
for (int i = 0; i < attrs.length; i++) {
Attr attr = attrs[i];
printWriter.print(' ');
printWriter.print(attr.getNodeName());
printWriter.print("=\""); //$NON-NLS-1$
normalizeAndPrint(attr.getNodeValue(), true);
printWriter.print('"');
}
if (node.getChildNodes().getLength() == 0) {
printWriter.print(" />"); //$NON-NLS-1$
printWriter.flush();
} else {
printWriter.print('>');
printWriter.flush();
Node child = node.getFirstChild();
while (child != null) {
writeAnyNode(child);
child = child.getNextSibling();
}
printWriter.print("</"); //$NON-NLS-1$
printWriter.print(node.getNodeName());
printWriter.print('>');
printWriter.flush();
}
}
示例14: getElementText
import org.w3c.dom.Element; //导入方法依赖的package包/类
public static String getElementText(Element element) throws DOMException{
for (Node child = element.getFirstChild(); child != null;
child = child.getNextSibling()) {
if(child.getNodeType() == Node.TEXT_NODE)
return child.getNodeValue();
}
return element.getNodeValue();
}
示例15: testGetChild
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test
public void testGetChild() throws Exception {
Document document = createDOMWithNS("ElementSample01.xml");
Element elemNode = (Element) document.getElementsByTagName("b:aaa").item(0);
elemNode.normalize();
Node firstChild = elemNode.getFirstChild();
Node lastChild = elemNode.getLastChild();
assertEquals(firstChild.getNodeValue(), "fjfjf");
assertEquals(lastChild.getNodeValue(), "fjfjf");
}