FileDocCategorySizeDatePackage
XMLFragment.javaAPI DocApache Ant 1.704818Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.util

XMLFragment

public class XMLFragment extends org.apache.tools.ant.ProjectComponent implements org.apache.tools.ant.DynamicElementNS
Use this class as a nested element if you want to get a literal DOM fragment of something nested into your task/type.

This is useful for tasks that want to deal with the "real" XML from the build file instead of objects.

Code heavily influenced by code written by Dominique Devienne.

since
Ant 1.7

Fields Summary
private Document
doc
private DocumentFragment
fragment
Constructors Summary
public XMLFragment()
Constructor for XMLFragment object.

        doc = JAXPUtils.getDocumentBuilder().newDocument();
        fragment = doc.createDocumentFragment();
    
Methods Summary
public voidaddText(java.lang.String s)
Add nested text, expanding properties as we go

param
s the text to add

        addText(fragment, s);
    
private voidaddText(org.w3c.dom.Node n, java.lang.String s)
Add text to a node.

param
n node
param
s value

        s = getProject().replaceProperties(s);
        //only text nodes that are non null after property expansion are added
        if (s != null && !s.trim().equals("")) {
            Text t = doc.createTextNode(s.trim());
            n.appendChild(t);
        }
    
public java.lang.ObjectcreateDynamicElement(java.lang.String uri, java.lang.String name, java.lang.String qName)
Creates a nested element.

param
uri the uri of the nested element
param
name the localname of the nested element
param
qName the qualified name of the nested element
return
an object that the element is applied to

        Element e = null;
        if (uri.equals("")) {
            e = doc.createElement(name);
        } else {
            e = doc.createElementNS(uri, qName);
        }
        fragment.appendChild(e);
        return new Child(e);
    
public org.w3c.dom.DocumentFragmentgetFragment()

return
the DocumentFragment that corresponds to the nested structure.

        return fragment;