com.github.simy4.xpath.dom4j.navigator.node.Dom4jDocument Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xpath-to-xml-dom4j Show documentation
Show all versions of xpath-to-xml-dom4j Show documentation
Convenient utility to build XML models by evaluating XPath expressions
package com.github.simy4.xpath.dom4j.navigator.node;
import com.github.simy4.xpath.XmlBuilderException;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import javax.xml.namespace.QName;
import java.util.Collections;
public final class Dom4jDocument extends AbstractDom4jNode {
public Dom4jDocument(Document document) {
super(document);
}
@Override
public QName getName() {
throw new UnsupportedOperationException("getName");
}
@Override
public Iterable> elements() {
final Element root = getNode().getRootElement();
return null == root ? Collections.>emptyList()
: Collections.>singletonList(new Dom4jElement(root));
}
@Override
public Iterable> attributes() {
return Collections.emptyList();
}
@Override
public Dom4jNode createAttribute(org.dom4j.QName attribute) throws XmlBuilderException {
throw new XmlBuilderException("Unable to append attribute to a document node " + getNode());
}
@Override
public Dom4jNode createElement(org.dom4j.QName element) throws XmlBuilderException {
if (null != getNode().getRootElement()) {
throw new XmlBuilderException("Unable to create element " + element + " . Root element already exist");
}
return new Dom4jElement(getNode().addElement(element));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy