Java Utililty Methods XML QName

List of utility methods to do XML QName

Description

The list of methods to do XML QName are organized into topic(s).

Method

booleanisPrimitiveType(final QName elementType)
is Primitive Type
if (elementType != null) {
    return CLASS_BINDING.containsKey(elementType.getLocalPart());
return false;
booleanisSameNamespace(QName q1, QName q2)
is Same Namespace
if (q1 == null && q2 != null)
    return false;
if (q1 != null && q2 == null)
    return false;
String p1 = q1 == null ? "" : q1.getPrefix() != null ? q1.getPrefix() : "";
String p2 = q2 == null ? "" : q2.getPrefix() != null ? q2.getPrefix() : "";
String n1 = q1 == null ? "" : q1.getNamespaceURI() != null ? q1.getNamespaceURI() : "";
String n2 = q2 == null ? "" : q2.getNamespaceURI() != null ? q2.getNamespaceURI() : "";
...
booleanisSameNamespaceAndDifferentPrefix(QName qName, Element element)
is Same Namespace And Different Prefix
return element.getNamespaceURI() != null && qName.getNamespaceURI().equals(element.getNamespaceURI())
        && (element.getPrefix() == null || !qName.getPrefix().equals(element.getPrefix()));
booleanisTagName(Element element, QName name)
is Tag Name
return (element.getLocalName().equals(name.getLocalPart())
        && (element.getNamespaceURI() != null && element.getNamespaceURI().equals(name.getNamespaceURI())));
booleanisType(Map> types, QName name, QName attributeName)
is Type
if (types == null) {
    return false;
Set<String> a = types.get(name);
return a != null && a.contains(attributeName.getLocalPart());
booleanisValidQName(String localPart)
Returns true if QName is valid for a given local part.
QName parseqn = DatatypeConverter.parseQName(localPart, nsc);
return parseqn != null;
booleanisWildcardType(QName type)
is Wildcard Type
return type.toString().equals("*");
voidmarshal(T value, Class elementClass, String packageName, QName q_name, OutputStream oStream)
marshal
final JAXBElement<T> jaxbEl = createRootElement(value, q_name, elementClass);
final JAXBContext jc = JAXBContext.newInstance(packageName);
final Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
m.marshal(jaxbEl, oStream);
JAXBElementmarshallJAXBElement(Class declaredType, QName name, Class scope, BoundType v)
marshall JAXB Element
if (v == null) {
    return null;
} else {
    return new JAXBElement<BoundType>(name, declaredType, scope, v);
StringmarshalToString(T obj, Class clazz, QName qname)
marshal To String
java.io.StringWriter sw = new java.io.StringWriter();
javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(clazz.getPackage().getName());
javax.xml.bind.Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(new JAXBElement(qname, clazz, obj), sw);
sw.close();
return sw.toString();
...