Search in sources :

Example 1 with Node

use of groovy.util.slurpersupport.Node in project groovy by apache.

the class XmlSlurper method startElement.

/* (non-Javadoc)
    * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
    */
public void startElement(final String namespaceURI, final String localName, final String qName, final Attributes atts) throws SAXException {
    addCdata();
    final Map<String, String> attributes = new NamespaceAwareHashMap();
    final Map<String, String> attributeNamespaces = new HashMap<String, String>();
    for (int i = atts.getLength() - 1; i != -1; i--) {
        if (atts.getURI(i).length() == 0) {
            attributes.put(atts.getQName(i), atts.getValue(i));
        } else {
            String key = new QName(atts.getURI(i), atts.getLocalName(i)).toString();
            attributes.put(key, atts.getValue(i));
            attributeNamespaces.put(key, atts.getURI(i));
        }
    }
    final Node newElement;
    if (namespaceURI.length() == 0) {
        newElement = new Node(currentNode, qName, attributes, attributeNamespaces, namespaceURI);
    } else {
        newElement = new Node(currentNode, localName, attributes, attributeNamespaces, namespaceURI);
    }
    if (currentNode != null) {
        currentNode.addChild(newElement);
    }
    stack.push(currentNode);
    currentNode = newElement;
}
Also used : NamespaceAwareHashMap(groovy.util.slurpersupport.NamespaceAwareHashMap) NamespaceAwareHashMap(groovy.util.slurpersupport.NamespaceAwareHashMap) HashMap(java.util.HashMap) QName(groovy.xml.QName) Node(groovy.util.slurpersupport.Node)

Example 2 with Node

use of groovy.util.slurpersupport.Node in project groovy by apache.

the class XmlSlurper method endElement.

/* (non-Javadoc)
    * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
    */
public void endElement(final String namespaceURI, final String localName, final String qName) throws SAXException {
    addCdata();
    Node oldCurrentNode = stack.pop();
    if (oldCurrentNode != null) {
        currentNode = oldCurrentNode;
    }
}
Also used : Node(groovy.util.slurpersupport.Node)

Example 3 with Node

use of groovy.util.slurpersupport.Node in project groovy-core by groovy.

the class XmlSlurper method endElement.

/* (non-Javadoc)
    * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
    */
public void endElement(final String namespaceURI, final String localName, final String qName) throws SAXException {
    addCdata();
    Node oldCurrentNode = stack.pop();
    if (oldCurrentNode != null) {
        currentNode = oldCurrentNode;
    }
}
Also used : Node(groovy.util.slurpersupport.Node)

Example 4 with Node

use of groovy.util.slurpersupport.Node in project groovy-core by groovy.

the class XmlSlurper method startElement.

/* (non-Javadoc)
    * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
    */
public void startElement(final String namespaceURI, final String localName, final String qName, final Attributes atts) throws SAXException {
    addCdata();
    final Map<String, String> attributes = new NamespaceAwareHashMap();
    final Map<String, String> attributeNamespaces = new HashMap<String, String>();
    for (int i = atts.getLength() - 1; i != -1; i--) {
        if (atts.getURI(i).length() == 0) {
            attributes.put(atts.getQName(i), atts.getValue(i));
        } else {
            String key = new QName(atts.getURI(i), atts.getLocalName(i)).toString();
            attributes.put(key, atts.getValue(i));
            attributeNamespaces.put(key, atts.getURI(i));
        }
    }
    final Node newElement;
    if (namespaceURI.length() == 0) {
        newElement = new Node(currentNode, qName, attributes, attributeNamespaces, namespaceURI);
    } else {
        newElement = new Node(currentNode, localName, attributes, attributeNamespaces, namespaceURI);
    }
    if (currentNode != null) {
        currentNode.addChild(newElement);
    }
    stack.push(currentNode);
    currentNode = newElement;
}
Also used : NamespaceAwareHashMap(groovy.util.slurpersupport.NamespaceAwareHashMap) NamespaceAwareHashMap(groovy.util.slurpersupport.NamespaceAwareHashMap) HashMap(java.util.HashMap) QName(groovy.xml.QName) Node(groovy.util.slurpersupport.Node)

Aggregations

Node (groovy.util.slurpersupport.Node)4 NamespaceAwareHashMap (groovy.util.slurpersupport.NamespaceAwareHashMap)2 QName (groovy.xml.QName)2 HashMap (java.util.HashMap)2