package org.opendaylight.controller.netconf.util.xml;
-import java.io.IOException;
-import java.util.*;
-
-import javax.annotation.Nullable;
-
-import org.w3c.dom.*;
-import org.xml.sax.SAXException;
-
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.SAXException;
+
+import javax.annotation.Nullable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class XmlElement {
}
public String getName() {
+ if (element.getLocalName()!=null && !element.getLocalName().equals("")){
+ return element.getLocalName();
+ }
return element.getTagName();
}
return element.getAttributeNS(namespace, attributeName);
}
+ public NodeList getElementsByTagName(String name) {
+ return element.getElementsByTagName(name);
+ }
+
public void appendChild(Element element) {
this.element.appendChild(element);
// Element newElement = (Element) element.cloneNode(true);
public String getNamespaceAttribute() {
String attribute = element.getAttribute(XmlUtil.XMLNS_ATTRIBUTE_KEY);
- Preconditions.checkState(attribute != null && !attribute.equals(""), "Element %s must specify a %s attribute",
- toString(), XmlUtil.XMLNS_ATTRIBUTE_KEY);
+ Preconditions.checkState(attribute != null && !attribute.equals(""), "Element %s must specify namespace",
+ toString());
return attribute;
}
prefix = "";
}
if (namespaces.containsKey(prefix) == false) {
- throw new IllegalArgumentException("Cannot find namespace for " + element + ". Prefix from content is "
+ throw new IllegalArgumentException("Cannot find namespace for " + XmlUtil.toString(element) + ". Prefix from content is "
+ prefix + ". Found namespaces " + namespaces);
}
return Maps.immutableEntry(prefix, namespaces.get(prefix));
return element.hashCode();
}
+ public boolean hasNamespace() {
+ try {
+ getNamespaceAttribute();
+ } catch (IllegalStateException e) {
+ try {
+ getNamespace();
+ } catch (IllegalStateException e1) {
+ return false;
+ }
+ return true;
+ }
+ return true;
+ }
+
private static interface ElementFilteringStrategy {
boolean accept(Element e);
}