Ejemplo n.º 1
0
  /**
   * This will invoke the <code>startElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param nsAtts <code>List</code> of namespaces to declare with the element or <code>null</code>.
   */
  private void startElement(Element element, Attributes nsAtts) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    // Allocate attribute list.
    AttributesImpl atts = (nsAtts != null) ? new AttributesImpl(nsAtts) : new AttributesImpl();

    List attributes = element.getAttributes();
    Iterator i = attributes.iterator();
    while (i.hasNext()) {
      Attribute a = (Attribute) i.next();
      atts.addAttribute(
          a.getNamespaceURI(),
          a.getName(),
          a.getQualifiedName(),
          getAttributeTypeName(a.getAttributeType()),
          a.getValue());
    }

    try {
      contentHandler.startElement(namespaceURI, localName, rawName, atts);
    } catch (SAXException se) {
      throw new JDOMException("Exception in startElement", se);
    }
  }
Ejemplo n.º 2
0
 /**
  * Appends a namespace declaration in the form of a xmlns attribute to an attribute list,
  * crerating this latter if needed.
  *
  * @param atts <code>AttributeImpl</code> where to add the attribute.
  * @param ns <code>Namespace</code> the namespace to declare.
  * @return <code>AttributeImpl</code> the updated attribute list.
  */
 private AttributesImpl addNsAttribute(AttributesImpl atts, Namespace ns) {
   if (this.declareNamespaces) {
     if (atts == null) {
       atts = new AttributesImpl();
     }
     atts.addAttribute(
         "", // namespace
         "", // local name
         "xmlns:" + ns.getPrefix(), // qualified name
         "CDATA", // type
         ns.getURI()); // value
   }
   return atts;
 }