Java Code Examples for org.jdom2.Element#getNamespacePrefix()

The following examples show how to use org.jdom2.Element#getNamespacePrefix() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: n2o-framework   File:    License: Apache License 2.0 5 votes vote down vote up
public static void installPrefix(Element element, Element rootElement) {
    if (element == null) return;
    if (rootElement.getNamespace() == null) return;
    if (element.getNamespacePrefix() == null) return;
    if (element.getNamespace() == null) return;
    if (element.getNamespace().getURI().equals(rootElement.getNamespace().getURI())) return;
    if (element.getNamespace().getURI().isEmpty()) return;
    if (rootElement.getAdditionalNamespaces().contains(element.getNamespace())) return;
    Namespace additional = element.getNamespace();
Example 2
 * Clones a set of attributes. Needs to be done this way to (i) break the
 * parental attachment to the attribute; and (ii) to fix any errant namespace
 * prefixes
 * @param element the element with the attributes to clone
 * @param defNS the default namespace
 * @return the List of clone attributes
private List<Attribute> cloneAttributes(Element element, Namespace defNS) {
    String prefix = element.getNamespacePrefix();
    List<Attribute> cloned = new ArrayList<Attribute>();
    for (Attribute attribute : element.getAttributes()) {
        String value = getAttributeValue(attribute, prefix, defNS);
        Attribute copy = new Attribute(attribute.getName(), value);
    return cloned;
Example 3
private String getElementFullName(final Element element) {
    final StringBuilder name = new StringBuilder(element.getNamespacePrefix());
    if (!element.getNamespacePrefix().isEmpty())
    return name.toString();
Example 4
Source Project: rome   File:    License: Apache License 2.0 5 votes vote down vote up
private static void collectUsedPrefixes(final Element el, final Set<String> collector) {

        final String prefix = el.getNamespacePrefix();
        if (prefix != null && prefix.length() > 0 && !collector.contains(prefix)) {

        final List<Element> kids = el.getChildren();
        for (final Element kid : kids) {
            // recursion- worth it
            collectUsedPrefixes(kid, collector);