use of org.w3c.dom.NodeList in project cw-android by commonsguy.
the class WeatherDemo method buildForecasts.
void buildForecasts(String raw) throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(raw)));
NodeList times = doc.getElementsByTagName("start-valid-time");
for (int i = 0; i < times.getLength(); i++) {
Element time = (Element) times.item(i);
Forecast forecast = new Forecast();
forecasts.add(forecast);
forecast.setTime(time.getFirstChild().getNodeValue());
}
NodeList temps = doc.getElementsByTagName("value");
for (int i = 0; i < temps.getLength(); i++) {
Element temp = (Element) temps.item(i);
Forecast forecast = forecasts.get(i);
forecast.setTemp(new Integer(temp.getFirstChild().getNodeValue()));
}
NodeList icons = doc.getElementsByTagName("icon-link");
for (int i = 0; i < icons.getLength(); i++) {
Element icon = (Element) icons.item(i);
Forecast forecast = forecasts.get(i);
forecast.setIcon(icon.getFirstChild().getNodeValue());
}
}
use of org.w3c.dom.NodeList in project hackpad by dropbox.
the class XmlNode method getMatchingChildren.
XmlNode[] getMatchingChildren(Filter filter) {
ArrayList<XmlNode> rv = new ArrayList<XmlNode>();
NodeList nodes = this.dom.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (filter.accept(node)) {
rv.add(createImpl(node));
}
}
return rv.toArray(new XmlNode[rv.size()]);
}
use of org.w3c.dom.NodeList in project che by eclipse.
the class Element method hasChildren.
/**
* Returns {@code true} if element has at least one child or {@code false} if doesn't
*
* @return {@code true} if element has at least one child or {@code false} if doesn't
* @throws XMLTreeException
* when this element has been removed from xml tree
*/
public boolean hasChildren() {
checkNotRemoved();
final NodeList childNodes = delegate.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
if (childNodes.item(i).getNodeType() == ELEMENT_NODE) {
return true;
}
}
return false;
}
use of org.w3c.dom.NodeList in project che by eclipse.
the class Element method removeChildren.
/**
* Removes children which names equal to given name
*
* @param name
* name to remove children
* @return this element instance
* @throws XMLTreeException
* when this element has been removed from xml tree
*/
public Element removeChildren(String name) {
checkNotRemoved();
final List<Node> matched = new LinkedList<>();
final NodeList nodes = delegate.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
if (name.equals(nodes.item(i).getNodeName())) {
matched.add(nodes.item(i));
}
}
for (Node node : matched) {
asElement(node).remove();
}
return this;
}
use of org.w3c.dom.NodeList in project che by eclipse.
the class Element method fetchText.
private String fetchText() {
final StringBuilder sb = new StringBuilder();
final NodeList childNodes = delegate.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
if (childNodes.item(i).getNodeType() == TEXT_NODE) {
sb.append(childNodes.item(i).getTextContent());
}
}
return sb.toString();
}
Aggregations