private void parse(Document doc) { NodeList nodeList = doc.getChildNodes(); for (int count = 0; count < nodeList.getLength(); count++) { Node node = nodeList.item(count); if (node.getNodeType() == Node.ELEMENT_NODE && node.hasChildNodes()) { parseAttrList(node.getChildNodes()); } } }
private static boolean isElementNode(Node node, String name) { return node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name); }
private void addToDependencyMapFromXML (Map<String, List<ExternalExtensionDependency>> dependencies, Element eElement, String platform) { if (eElement.getElementsByTagName(platform).item(0) != null) { Element project = (Element)eElement.getElementsByTagName(platform).item(0); ArrayList<ExternalExtensionDependency> deps = new ArrayList<ExternalExtensionDependency>(); if (project.getTextContent().trim().equals("")) { // No dependencies required } else if (project.getTextContent().trim().equals("null")) { // Not supported deps = null; } else { NodeList nList = project.getElementsByTagName("dependency"); for (int i = 0; i < nList.getLength(); i++) { Node nNode = nList.item(i); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element dependencyNode = (Element)nNode; boolean external = Boolean.parseBoolean(dependencyNode.getAttribute("external")); deps.add(new ExternalExtensionDependency(dependencyNode.getTextContent(), external)); } } } dependencies.put(platform, deps); } }
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());
public static String text(Node node) { if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) { return node.getNodeValue(); } if (node.hasChildNodes()) { return text(node.getChildNodes()); } return ""; }
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(); }
private void readPackageConfigFromXml(Node node) throws IOException { NodeList childNodes = node.getChildNodes(); if (childNodes.getLength() > 0) { for (int j = 0, n = childNodes.getLength(); j < n; j++) { Node child = childNodes.item(j); if (child.getNodeType() == Node.ELEMENT_NODE) { Element check = (Element) child; String tagName = check.getTagName(); String value = check.getAttribute(ATTR_VALUE); String name = check.getAttribute(ATTR_NAME); if (tagName.equals(ATTR_CONFIG_FIELD)) { mPackageFields.put(name, value); } else { System.err.println("unknown package config tag " + tagName); } } } } }
/** * Reconstructs the resource from the XML file */ @SuppressWarnings("unchecked") public SsurgeonWordlist(Element rootElt) { id = rootElt.getAttribute("id"); NodeList wordEltNL = rootElt.getElementsByTagName(WORD_ELT); for (int i=0; i<wordEltNL.getLength(); i++) { Node node = wordEltNL.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String word = Ssurgeon.getEltText((Element) node); words.add(word); } } }
/** * Given a node, determine if it is a namespace node. * * @param node * * @return boolean Returns true if this is a namespace node; otherwise, returns false. */ private boolean isNamespaceNode(Node node) { if ((null != node) && (node.getNodeType() == Node.ATTRIBUTE_NODE) && (node.getNodeName().startsWith("xmlns:") || node.getNodeName().equals("xmlns"))) { return true; } else { return false; } }
private void visit( Node n ) throws SAXException { setCurrentLocation( n ); // if a case statement gets too big, it should be made into a separate method. switch(n.getNodeType()) { case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: String value = n.getNodeValue(); receiver.characters( value.toCharArray(), 0, value.length() ); break; case Node.ELEMENT_NODE: visit( (Element)n ); break; case Node.ENTITY_REFERENCE_NODE: receiver.skippedEntity(n.getNodeName()); break; case Node.PROCESSING_INSTRUCTION_NODE: ProcessingInstruction pi = (ProcessingInstruction)n; receiver.processingInstruction(pi.getTarget(),pi.getData()); break; } }
private String text(Node n){ String text = null; switch(n.getNodeType()){ case Node.TEXT_NODE: text = n.getNodeValue(); if(text != null) text = text.trim(); break; case Node.CDATA_SECTION_NODE: text = n.getNodeValue(); break; default: //AQUtility.debug("unknown", n); } if(text == null) text = ""; return text; }
private static String parseTextNode(Node exampleNode) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < exampleNode.getChildNodes().getLength(); i++) { Node node = exampleNode.getChildNodes().item(i); if (node.getNodeType() == Node.CDATA_SECTION_NODE || node.getNodeType() == Node.TEXT_NODE) { buffer.append(node.getNodeValue()); } } return buffer.toString().trim(); } }
/** * For the given element, finds the first child Element with the given tag. */ private static Element getFirstTag(Element element, String tag) { try { NodeList nodeList = element.getElementsByTagName(tag); if (nodeList.getLength() == 0) return null; for (int i=0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) return (Element) node; } } catch (Exception e) { log.warning("Error getting first tag "+tag+" under element="+element); } return null; }
void outputContent(NamedNodeMap nodes, StringBuilder buf) { for (int i = 0; i < nodes.getLength(); ++i) { Node n = nodes.item(i); if (n.getNodeType() != Node.ATTRIBUTE_NODE || (!n.getNodeName().startsWith("xmlns:") && !n.getNodeName().equals("xmlns"))) { outputContent(n, buf); } } }
public static String toString(Object o) { if (o instanceof Node) { if (((Node) o).getNodeType() == Node.TEXT_NODE) { return ((Node) o).getNodeValue(); } } if (o instanceof NodeList) { return toString((NodeList) o); } return o.toString(); }
private static String extractContent(Element element, String defaultStr) { if ( element == null ) { return defaultStr; } NodeList children = element.getChildNodes(); StringBuilder result = new StringBuilder(""); for ( int i = 0; i < children.getLength() ; i++ ) { if ( children.item( i ).getNodeType() == Node.TEXT_NODE || children.item( i ).getNodeType() == Node.CDATA_SECTION_NODE ) { result.append( children.item( i ).getNodeValue() ); } } return result.toString().trim(); }
private void writeUpdatedTMX (TiledMap tiledMap, FileHandle tmxFileHandle) throws IOException { Document doc; DocumentBuilder docBuilder; DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); try { docBuilder = docFactory.newDocumentBuilder(); doc = docBuilder.parse(tmxFileHandle.read()); Node map = doc.getFirstChild(); while (map.getNodeType() != Node.ELEMENT_NODE || map.getNodeName() != "map") { if ((map = map.getNextSibling()) == null) { throw new GdxRuntimeException("Couldn't find map node!"); } } setProperty(doc, map, "atlas", settings.tilesetOutputDirectory + "/" + settings.atlasOutputName + ".atlas"); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); outputDir.mkdirs(); StreamResult result = new StreamResult(new File(outputDir, tmxFileHandle.name())); transformer.transform(source, result); } catch (ParserConfigurationException e) { throw new RuntimeException("ParserConfigurationException: " + e.getMessage()); } catch (SAXException e) { throw new RuntimeException("SAXException: " + e.getMessage()); } catch (TransformerConfigurationException e) { throw new RuntimeException("TransformerConfigurationException: " + e.getMessage()); } catch (TransformerException e) { throw new RuntimeException("TransformerException: " + e.getMessage()); } }
private void readLibPatternsFromXml(Node node) throws IOException { NodeList childNodes = node.getChildNodes(); if (childNodes.getLength() > 0) { for (int j = 0, n = childNodes.getLength(); j < n; j++) { Node child = childNodes.item(j); if (child.getNodeType() == Node.ELEMENT_NODE) { Element check = (Element) child; String tagName = check.getTagName(); String value = check.getAttribute(ATTR_VALUE); if (tagName.equals(ATTR_PATTERN)) { addToPatterns(value, mSoFilePattern); } else { System.err.println("unknown dex tag " + tagName); } } } } }
private void writeUpdatedTMX (TiledMap tiledMap, FileHandle tmxFileHandle) throws IOException { Document doc; DocumentBuilder docBuilder; DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); try { docBuilder = docFactory.newDocumentBuilder(); doc = docBuilder.parse(tmxFileHandle.read()); Node map = doc.getFirstChild(); while (map.getNodeType() != Node.ELEMENT_NODE || map.getNodeName() != "map") { if ((map = map.getNextSibling()) == null) { throw new GdxRuntimeException("Couldn't find map node!"); } } setProperty(doc, map, "atlas", settings.tilesetOutputDirectory + "/" + settings.atlasOutputName + ".atlas"); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); outputDir.mkdirs(); StreamResult result = new StreamResult(new File(outputDir, tmxFileHandle.name())); transformer.transform(source, result); } catch (ParserConfigurationException e) { throw new RuntimeException("ParserConfigurationException: " + e.getMessage()); } catch (SAXException e) { throw new RuntimeException("SAXException: " + e.getMessage()); } catch (TransformerConfigurationException e) { throw new RuntimeException("TransformerConfigurationException: " + e.getMessage()); } catch (TransformerException e) { throw new RuntimeException("TransformerException: " + e.getMessage()); } }
public BeanDefinitionHolder decorateBeanDefinitionIfRequired( Element ele, BeanDefinitionHolder definitionHolder, @Nullable BeanDefinition containingBd) { BeanDefinitionHolder finalDefinition = definitionHolder; // Decorate based on custom attributes first. NamedNodeMap attributes = ele.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node node = attributes.item(i); finalDefinition = decorateIfRequired(node, finalDefinition, containingBd); } // Decorate based on custom nested elements. NodeList children = ele.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { finalDefinition = decorateIfRequired(node, finalDefinition, containingBd); } } return finalDefinition; }