Ejemplo n.º 1
0
  /**
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {

    if (args.length != 1) {
      printUsage();
    }

    filename = args[0];

    XMLInputFactory xmlif = null;
    try {
      xmlif = XMLInputFactory.newInstance();
      xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
      xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
      xmlif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
      xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    System.out.println("XMLInputFactory: " + xmlif);
    System.out.println("filename = " + filename);

    XMLStreamReader xmlr = null;
    try {

      FileInputStream fis = new FileInputStream(filename);

      xmlr = xmlif.createXMLStreamReader(fis);

    } catch (Exception ex) {
      ex.printStackTrace();
    }

    for (int event = xmlr.next(); event != XMLStreamConstants.END_DOCUMENT; event = xmlr.next()) {
      if (event == XMLStreamConstants.START_ELEMENT) {
        String element = xmlr.getLocalName();
      }
    }
  }
Ejemplo n.º 2
0
  private static void printAttributes(XMLStreamReader xmlr) {

    if (xmlr.getAttributeCount() > 0) {

      int count = xmlr.getAttributeCount();
      for (int i = 0; i < count; i++) {

        QName name = xmlr.getAttributeName(i);
        String namespace = xmlr.getAttributeNamespace(i);
        String type = xmlr.getAttributeType(i);
        String prefix = xmlr.getAttributePrefix(i);
        String value = xmlr.getAttributeValue(i);

        System.out.println(
            "\tAttribute: {" + namespace + "}:" + name.toString() + "(" + type + ")=" + value);
      }
    }
  }