Example usage for org.xml.sax Attributes getQName

List of usage examples for org.xml.sax Attributes getQName

Introduction

In this page you can find the example usage for org.xml.sax Attributes getQName.

Prototype

public abstract String getQName(int index);

Source Link

Document

Look up an attribute's XML qualified (prefixed) name by index.

Usage

From source file:net.ontopia.xml.ContentWriter.java

@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
        throws SAXException {
    try {/*w ww .  j av  a  2 s  .  co  m*/
        out.write("<" + localName);
        if (atts != null) {
            for (int i = 0; i < atts.getLength(); i++)
                out.write(" " + atts.getQName(i) + "=\"" + escape(atts.getValue(i)) + "\"");
        }
        out.write('>');
    } catch (IOException e) {
        throw new SAXException(e);
    }

    content = false;
}

From source file:net.ontopia.xml.CanonicalPrinter.java

@Override
public void startElement(String uri, String localName, String name, Attributes atts) {
    // first: sort attributes
    String[] attNames = new String[atts.getLength()];
    for (int i = 0; i < atts.getLength(); i++) {
        attNames[i] = atts.getQName(i);
    }/*from   ww w . j av  a  2 s  . c om*/
    java.util.Arrays.sort(attNames);

    // then write it out in sorted order
    writer.print("<" + name);
    for (int i = 0; i < attNames.length; i++)
        writer.print(" " + attNames[i] + "=\"" + escape(atts.getValue(attNames[i])) + "\"");
    writer.print(">");
}

From source file:SAXCopy.java

public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
    System.out.println("<" + qName);
    if (namespaceBegin) {
        System.out.print(" xmlns:" + currentNamespace + "=\"" + currentNamespaceUri + "\"");
        namespaceBegin = false;//from  w w  w.j a va2 s.  c om
    }
    for (int i = 0; i < atts.getLength(); i++) {
        System.out.print(" " + atts.getQName(i) + "=\\" + atts.getValue(i) + "\"");
    }
    System.out.print(">");
}

From source file:SAXCopy.java

public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
    out.print("<" + qName);
    if (namespaceBegin) {
        out.print(" xmlns:" + currentNamespace + "=\"" + currentNamespaceUri + "\"");
        namespaceBegin = false;/*  ww w  .  j ava 2  s  . c  om*/
    }
    for (int i = 0; i < atts.getLength(); i++) {
        out.print(" " + atts.getQName(i) + "=\\" + atts.getValue(i) + "\"");
    }
    out.print(">");
}

From source file:com.redhat.rhn.common.util.AttributeCopyRule.java

/** {@inheritDoc} */
public void begin(String namespace, String name, Attributes attributes) throws Exception {
    Object param = digester.peek();
    Method me;//from   w ww  . j  a  va  2s.co  m
    try {
        me = param.getClass().getMethod("put", new Class[] { Object.class, Object.class });
    } catch (NoSuchMethodException e) {
        return;
    }

    for (int i = 0; i < attributes.getLength(); i++) {
        me.invoke(param, attributes.getQName(i), attributes.getValue(i));
    }
}

From source file:MainClass.java

public void startElement(String uri, String localName, String qname, Attributes attr) {
    System.out.println("Start element: local name: " + localName + " qname: " + qname + " uri: " + uri);
    int attrCount = attr.getLength();
    if (attrCount > 0) {
        System.out.println("Attributes:");
        for (int i = 0; i < attrCount; i++) {
            System.out.println("  Name : " + attr.getQName(i));
            System.out.println("  Type : " + attr.getType(i));
            System.out.println("  Value: " + attr.getValue(i));
        }//from  w w w  .  j  a  v  a2 s . c o  m
    }
}

From source file:SAXSample.java

public void startElement(String uri, String localName, String qName, Attributes attributes) {
    if (qName.equalsIgnoreCase("books")) {
        books = new SAXBooks();
    } else if (qName.equalsIgnoreCase("book")) {
        SAXBook book = new SAXBook();
        for (int i = 0; i < attributes.getLength(); i++) {
            if (attributes.getQName(i).equalsIgnoreCase("category")) {
                book.setCategory(attributes.getValue(i));
            }//from ww w  .  j a  va2 s  .  co m
        }
        books.addBook(book);
    } else if (qName.equalsIgnoreCase("author")) {
        this.readingAuthor = true;
    } else if (qName.equalsIgnoreCase("title")) {
        this.readingTitle = true;
    } else if (qName.equalsIgnoreCase("price")) {
        this.readingPrice = true;
    } else {
        System.out.println("Unknown element: " + qName);
    }
}

From source file:io.lightlink.excel.CopyingTemplateHandler.java

protected void printElementStart(String eName, Attributes attrs) throws SAXException {
    emit("\n<" + eName);

    if (attrs != null) {
        for (int i = 0; i < attrs.getLength(); i++) {
            String aName = attrs.getLocalName(i); // Attr name

            if ("".equals(aName)) {
                aName = attrs.getQName(i);
            }/*from  w ww .java  2 s .  com*/

            emit(" " + aName + "=\"" + attrs.getValue(i) + "\"");
        }
    }

    emit(">");
}

From source file:FragmentContentHandler.java

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    Integer count = elementNameCount.get(qName);
    if (null == count) {
        count = 1;/*from ww  w.j  a va  2  s . c om*/
    } else {
        count++;
    }
    elementNameCount.put(qName, count);
    String childXPath = xPath + "/" + qName + "[" + count + "]";

    int attsLength = atts.getLength();
    for (int x = 0; x < attsLength; x++) {
        System.out.println(childXPath + "[@" + atts.getQName(x) + "='" + atts.getValue(x) + ']');
    }

    FragmentContentHandler child = new FragmentContentHandler(childXPath, xmlReader, this);
    xmlReader.setContentHandler(child);
}

From source file:MyContentHandler.java

public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
    System.out.println("-" + locator.getLineNumber() + "---Opening tag of an element");
    System.out.println("       Namespace: " + namespaceURI);
    System.out.println("      Local name: " + localName);
    System.out.println("  Qualified name: " + qName);
    for (int i = 0; i < atts.getLength(); i++) {
        System.out.println("       Attribute: " + atts.getQName(i) + "=\"" + atts.getValue(i) + "\"");
    }//from   w ww  .ja v  a2  s .co m
}