xmlparser.parsing.DomBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simplexml Show documentation
Show all versions of simplexml Show documentation
A clean and simple XML parser, serializer, and deserializer.
package xmlparser.parsing;
import xmlparser.model.XmlElement;
import xmlparser.model.XmlElement.XmlTextElement;
import java.util.Map;
public class DomBuilder implements EventParser {
private XmlElement root;
private XmlElement current;
public void startNode(final String name, final Map attrs) {
final XmlElement tmp = new XmlElement(this.current, name, attrs);
if (this.current != null) this.current.appendChild(tmp);
else this.root = tmp;
this.current = tmp;
}
public void endNode() {
this.current = this.current.parent;
}
public void someText(final String txt) {
if (txt == null || txt.isEmpty()) return;
this.current.children.add(new XmlTextElement(this.current, txt.trim()));
}
public XmlElement getRoot() {
return this.root;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy