private void appendElement()

in src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java [2188:2221]


    private void appendElement(Document doc, Element parent, Node children, XmlSchema schema) {
        Element elTmp = (Element)children;
        Element el = createNewElement(doc, elTmp.getLocalName(), schema.getSchemaNamespacePrefix(),
                                      XmlSchema.SCHEMA_NS);
        NamedNodeMap attributes = el.getAttributes();
        // check if child node has attribute
        // create new element and append it if found
        int attributeLength = attributes.getLength();
        for (int i = 0; i < attributeLength; i++) {
            Node n = attributes.item(i);
            // assuming attributes got to throw exception if not later
            el.setAttribute(n.getNodeName(), n.getNodeValue());
        }

        // check any descendant of this node
        // if there then append its child
        NodeList decendants = el.getChildNodes();
        int decendantLength = decendants.getLength();
        for (int i = 0; i < decendantLength; i++) {
            Node n = decendants.item(i);
            short nodeType = n.getNodeType();
            if (nodeType == Node.TEXT_NODE) {
                String nValue = n.getNodeValue();
                Text t = doc.createTextNode(nValue);
                el.appendChild(t);
            } else if (nodeType == Node.CDATA_SECTION_NODE) {
                String nValue = n.getNodeValue();
                CDATASection s = doc.createCDATASection(nValue);
                el.appendChild(s);
            } else if (nodeType == Node.ELEMENT_NODE) {
                appendElement(doc, el, n, schema);
            }
        }
    }