Java Code Examples for org.w3c.dom.Node#hasAttributes()
The following examples show how to use
org.w3c.dom.Node#hasAttributes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManifestAttributes.java From Box with Apache License 2.0 | 6 votes |
private void parseAttrList(NodeList nodeList) { for (int count = 0; count < nodeList.getLength(); count++) { Node tempNode = nodeList.item(count); if (tempNode.getNodeType() == Node.ELEMENT_NODE && tempNode.hasAttributes() && tempNode.hasChildNodes()) { String name = null; NamedNodeMap nodeMap = tempNode.getAttributes(); for (int i = 0; i < nodeMap.getLength(); i++) { Node node = nodeMap.item(i); if (node.getNodeName().equals("name")) { name = node.getNodeValue(); break; } } if (name != null && tempNode.getNodeName().equals("attr")) { parseValues(name, tempNode.getChildNodes()); } else { parseAttrList(tempNode.getChildNodes()); } } } }
Example 2
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
private void print(StringBuilder buf, Node node, int level) { String indent = String.join("", Collections.nCopies(level * 2, " ")); buf.append(String.format("%s%s%n", indent, node.getNodeName())); if (node.hasAttributes()) { for (int i = 0; i < node.getAttributes().getLength(); i++) { Node attr = node.getAttributes().item(i); buf.append(String.format("%s #%s=%s%n", indent, attr.getNodeName(), attr.getNodeValue())); } } if (node.hasChildNodes()) { for (int i = 0; i < node.getChildNodes().getLength(); i++) { Node child = node.getChildNodes().item(i); print(buf, child, level + 1); } } }
Example 3
Source File: SchemaDOM.java From Bytecoder with Apache License 2.0 | 6 votes |
public static void traverse(Node node, int depth) { indent(depth); System.out.print("<"+node.getNodeName()); if (node.hasAttributes()) { NamedNodeMap attrs = node.getAttributes(); for (int i=0; i<attrs.getLength(); i++) { System.out.print(" "+((Attr)attrs.item(i)).getName()+"=\""+((Attr)attrs.item(i)).getValue()+"\""); } } if (node.hasChildNodes()) { System.out.println(">"); depth+=4; for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { traverse(child, depth); } depth-=4; indent(depth); System.out.println("</"+node.getNodeName()+">"); } else { System.out.println("/>"); } }
Example 4
Source File: ManifestAttributes.java From jadx with Apache License 2.0 | 6 votes |
private void parseAttrList(NodeList nodeList) { for (int count = 0; count < nodeList.getLength(); count++) { Node tempNode = nodeList.item(count); if (tempNode.getNodeType() == Node.ELEMENT_NODE && tempNode.hasAttributes() && tempNode.hasChildNodes()) { String name = null; NamedNodeMap nodeMap = tempNode.getAttributes(); for (int i = 0; i < nodeMap.getLength(); i++) { Node node = nodeMap.item(i); if (node.getNodeName().equals("name")) { name = node.getNodeValue(); break; } } if (name != null && tempNode.getNodeName().equals("attr")) { parseValues(name, tempNode.getChildNodes()); } else { parseAttrList(tempNode.getChildNodes()); } } } }
Example 5
Source File: TSTokenView.java From alpha-wallet-android with MIT License | 6 votes |
private String htmlAttributes(Node attribute) { StringBuilder sb = new StringBuilder(); if (attribute.hasAttributes()) { for (int i = 0; i < attribute.getAttributes().getLength(); i++) { Node node = attribute.getAttributes().item(i); sb.append(" "); sb.append(node.getLocalName()); sb.append("=\""); sb.append(node.getTextContent()); sb.append("\""); } } return sb.toString(); }
Example 6
Source File: AbstractTestCase.java From marklogic-contentpump with Apache License 2.0 | 6 votes |
protected void walkDOMAttr(NodeList nodes, Set<String> sb) { for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { if (LOG.isDebugEnabled()) LOG.debug(n.getNodeName()); } if (n.hasAttributes()) { NamedNodeMap nnMap = n.getAttributes(); for (int j = 0; j < nnMap.getLength(); j++) { Attr attr = (Attr) nnMap.item(j); String tmp = n.getNodeName() + "@" + attr.getName() + "=" + attr.getValue().replaceAll("\\s+", ""); tmp += "#parent is " + attr.getParentNode(); tmp += "#nextSibling is " + attr.getNextSibling(); if (LOG.isDebugEnabled()) LOG.debug(tmp); sb.add(tmp); } } if (n.hasChildNodes()) { walkDOMAttr(n.getChildNodes(), sb); } } }
Example 7
Source File: AbstractTestCase.java From marklogic-contentpump with Apache License 2.0 | 6 votes |
protected void walkDOMAttr(NodeList nodes, StringBuilder sb) { for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { if (LOG.isDebugEnabled()) LOG.debug(n.getNodeName()); } if (n.hasAttributes()) { ArrayList<String> list = new ArrayList<String>(); sb.append(n.getNodeName()).append("#\n"); NamedNodeMap nnMap = n.getAttributes(); for (int j = 0; j < nnMap.getLength(); j++) { Attr attr = (Attr) nnMap.item(j); String tmp = "@" + attr.getName() + "=" + attr.getValue(); list.add(tmp); list.add("#isSpecified:" + attr.getSpecified() + "\n"); } Collections.sort(list); sb.append(list.toString()); } sb.append("\n"); if (n.hasChildNodes()) { walkDOMAttr(n.getChildNodes(), sb); } } }
Example 8
Source File: JPEGMetadata.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private boolean wantAlpha(Node transparency) { boolean returnValue = false; Node alpha = transparency.getFirstChild(); // Alpha must be first if present if (alpha.getNodeName().equals("Alpha")) { if (alpha.hasAttributes()) { String value = alpha.getAttributes().getNamedItem("value").getNodeValue(); if (!value.equals("none")) { returnValue = true; } } } transparencyDone = true; return returnValue; }
Example 9
Source File: JPEGMetadata.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private boolean wantAlpha(Node transparency) { boolean returnValue = false; Node alpha = transparency.getFirstChild(); // Alpha must be first if present if (alpha.getNodeName().equals("Alpha")) { if (alpha.hasAttributes()) { String value = alpha.getAttributes().getNamedItem("value").getNodeValue(); if (!value.equals("none")) { returnValue = true; } } } transparencyDone = true; return returnValue; }
Example 10
Source File: JPEGMetadata.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private boolean wantAlpha(Node transparency) { boolean returnValue = false; Node alpha = transparency.getFirstChild(); // Alpha must be first if present if (alpha.getNodeName().equals("Alpha")) { if (alpha.hasAttributes()) { String value = alpha.getAttributes().getNamedItem("value").getNodeValue(); if (!value.equals("none")) { returnValue = true; } } } transparencyDone = true; return returnValue; }
Example 11
Source File: XrdsParserImpl.java From openid4java with Apache License 2.0 | 5 votes |
private int getPriority(Node node) { if (node.hasAttributes()) { Node priority = node.getAttributes().getNamedItem(XRD_ATTR_PRIORITY); if (priority != null) return Integer.parseInt(priority.getNodeValue()); else return XrdsServiceEndpoint.LOWEST_PRIORITY; } return 0; }
Example 12
Source File: TimedTextMarkupLanguageParser.java From MLib with GNU General Public License v3.0 | 5 votes |
/** * Build a map of used colors within the TTML file. */ private void buildColorMap() { final NodeList styleData = doc.getElementsByTagName("tt:style"); for (int i = 0; i < styleData.getLength(); i++) { final Node subnode = styleData.item(i); if (subnode.hasAttributes()) { final NamedNodeMap attrMap = subnode.getAttributes(); final Node idNode = attrMap.getNamedItem("xml:id"); final Node colorNode = attrMap.getNamedItem("tts:color"); if (idNode != null && colorNode != null) { colorMap.put(idNode.getNodeValue(), colorNode.getNodeValue()); } } } }
Example 13
Source File: LayoutParser.java From android-string-extractor-plugin with MIT License | 5 votes |
private void processNode(List<StringOccurrence> stringOccurrences, Node node) { if (node.hasChildNodes()) processNodes(stringOccurrences, node.getChildNodes()); if (!node.hasAttributes()) return; NamedNodeMap attributes = node.getAttributes(); Node idAttribute = attributes.getNamedItem("android:id"); Node textAttribute = attributes.getNamedItem("android:text"); Node hintAttribute = attributes.getNamedItem("android:hint"); if (!ignoreMissingId) validateNode(idAttribute, textAttribute, hintAttribute); if (idAttribute == null || (textAttribute == null && hintAttribute == null)) return; String id = stripIdPrefix(idAttribute.getNodeValue()); if (textAttribute != null) { if (!isDataBinding(textAttribute.getNodeValue())) { stringOccurrences.add( new StringOccurrence(id, "text", textAttribute.getNodeValue())); } } if (hintAttribute != null) { if (!isDataBinding(hintAttribute.getNodeValue())) { stringOccurrences.add( new StringOccurrence(id, "hint", hintAttribute.getNodeValue())); } } }
Example 14
Source File: JPEGMetadata.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private boolean wantAlpha(Node transparency) { boolean returnValue = false; Node alpha = transparency.getFirstChild(); // Alpha must be first if present if (alpha.getNodeName().equals("Alpha")) { if (alpha.hasAttributes()) { String value = alpha.getAttributes().getNamedItem("value").getNodeValue(); if (!value.equals("none")) { returnValue = true; } } } transparencyDone = true; return returnValue; }
Example 15
Source File: WSDL11SOAPOperationExtractor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private String getNodeName(Node node) { if (node.hasAttributes() && node.getAttributes().getNamedItem(NAME_ATTRIBUTE) != null) { return node.getAttributes().getNamedItem(NAME_ATTRIBUTE).getNodeValue(); } if (node.hasAttributes() && node.getAttributes().getNamedItem(SOAPToRESTConstants.REF_ATTRIBUTE) != null) { return node.getAttributes().getNamedItem(SOAPToRESTConstants.REF_ATTRIBUTE).getNodeValue().contains(":") ? node.getAttributes().getNamedItem(SOAPToRESTConstants.REF_ATTRIBUTE).getNodeValue().split(":")[1] : node.getAttributes().getNamedItem(SOAPToRESTConstants.REF_ATTRIBUTE).getNodeValue(); } return SOAPToRESTConstants.EMPTY_STRING; }
Example 16
Source File: JPEGMetadata.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private boolean wantAlpha(Node transparency) { boolean returnValue = false; Node alpha = transparency.getFirstChild(); // Alpha must be first if present if (alpha.getNodeName().equals("Alpha")) { if (alpha.hasAttributes()) { String value = alpha.getAttributes().getNamedItem("value").getNodeValue(); if (!value.equals("none")) { returnValue = true; } } } transparencyDone = true; return returnValue; }
Example 17
Source File: SOAPRequestBuilder.java From cougar with Apache License 2.0 | 5 votes |
public void iterate(SOAPEnvelope envelope, Node node, SOAPElement parentElement) throws SOAPException { // if the node is an element then process it and it's children if(node instanceof Element){ Element elemt = (Element) node; String localName = elemt.getNodeName(); SOAPElement newParent = parentElement.addChildElement(localName,"bas", nameSpace); // If the node has attributes then process them if(node.hasAttributes()){ AttributeMap map = (AttributeMap) node.getAttributes(); for (int x = 0; x < map.getLength(); x++) { String name = map.item(x).getNodeName(); newParent.setAttribute(name, map.item(x).getNodeValue()); } } org.w3c.dom.NodeList childNodes = node.getChildNodes(); // for each of this nodes children recursively call this method for (int i = 0; i < childNodes.getLength(); i++) { iterate(envelope, childNodes.item(i), newParent); } } else if (node.getNodeType() == Node.TEXT_NODE){ // Node is a text node so add it's value String value = node.getNodeValue(); if (value==null) { parentElement.addTextNode(""); } else { parentElement.addTextNode(value); } } // Else is some other kind of node which can be ignored }
Example 18
Source File: CustomTagConverter.java From TranskribusCore with GNU General Public License v3.0 | 5 votes |
private Node findAttributeNode(Node node, String attName) { if (node.hasAttributes()) { // get attributes names and values NamedNodeMap nodeMap = node.getAttributes(); for (int i = 0; i < nodeMap.getLength(); i++) { if (nodeMap.item(i).getNodeName().equals(attName)) { return nodeMap.item(i); } } } return null; }
Example 19
Source File: TimedTextMarkupLanguageParser.java From MLib with GNU General Public License v3.0 | 4 votes |
/** * Build the Subtitle objects from TTML content. */ private void buildFilmListFlash() throws Exception { final NodeList subtitleData = doc.getElementsByTagName("p"); for (int i = 0; i < subtitleData.getLength(); i++) { final Subtitle subtitle = new Subtitle(); final Node subnode = subtitleData.item(i); if (subnode.hasAttributes()) { // retrieve the begin and end attributes... final NamedNodeMap attrMap = subnode.getAttributes(); final Node beginNode = attrMap.getNamedItem("begin"); final Node endNode = attrMap.getNamedItem("end"); if (beginNode != null && endNode != null) { subtitle.begin = parseFlash(beginNode.getNodeValue()); subtitle.end = parseFlash(endNode.getNodeValue()); final StyledString textContent = new StyledString(); textContent.setColor(color); // sicher ist sicher textContent.setText(subnode.getTextContent()); final Node col = attrMap.getNamedItem("tts:color"); if (col != null) { textContent.setColor(col.getNodeValue()); } else { final NodeList childNodes = subnode.getChildNodes(); for (int j = 0; j < childNodes.getLength(); j++) { final Node node = childNodes.item(j); if (node.getNodeName().equalsIgnoreCase("span")) { //retrieve the text and color information... final NamedNodeMap attr = node.getAttributes(); final Node co = attr.getNamedItem("tts:color"); textContent.setColor(co.getNodeValue()); } } } subtitle.listOfStrings.add(textContent); } } subtitleList.add(subtitle); } }
Example 20
Source File: ModifiedCompoundXMLConverter.java From biojava with GNU Lesser General Public License v2.1 | 4 votes |
private static String getAttribute(Node node, String attr){ if( ! node.hasAttributes()) return null; NamedNodeMap atts = node.getAttributes(); if ( atts == null) return null; Node att = atts.getNamedItem(attr); if ( att == null) return null; String value = att.getTextContent(); return value; }