Пример #1
0
  public void testSimpleValidExternalSubset() throws XMLStreamException {
    String XML = "<!DOCTYPE root SYSTEM 'myurl' >" + "<root>text</root>";
    String EXT_ENTITY_VALUE = "just testing";
    String EXT_SUBSET = "<!ELEMENT root (#PCDATA)>\n" + "<!-- comments are ok!!! -->";

    XMLStreamReader sr = getReader(XML, true, new SimpleResolver(EXT_SUBSET));
    assertTokenType(DTD, sr.next());
    assertTokenType(START_ELEMENT, sr.next());
    assertEquals("root", sr.getLocalName());
    assertTokenType(CHARACTERS, sr.next());
    assertEquals("text", getAndVerifyText(sr));
    assertTokenType(END_ELEMENT, sr.next());
    sr.close();
  }
Пример #2
0
  @Override
  public DbData readData(InputStream in) throws XMLStreamException {
    XMLStreamReader sr = _staxInFactory.createXMLStreamReader(in);
    DbData result = new DbData();

    sr.nextTag();
    expectTag(FIELD_TABLE, sr);

    try {
      while (sr.nextTag() == XMLStreamReader.START_ELEMENT) {
        result.addRow(readRow(sr));
      }
    } catch (IllegalArgumentException iae) {
      throw new XMLStreamException("Data problem: " + iae.getMessage(), sr.getLocation());
    }

    sr.close();
    return result;
  }
Пример #3
0
    @Override
    protected void map(LongWritable key, Text value, Mapper.Context context)
        throws IOException, InterruptedException {
      String document = value.toString();
      System.out.println("'" + document + "'");
      try {
        XMLStreamReader reader =
            XMLInputFactory.newInstance()
                .createXMLStreamReader(new ByteArrayInputStream(document.getBytes()));
        String propertyName = "";
        String propertyValue = "";
        String currentElement = "";
        while (reader.hasNext()) {
          int code = reader.next();
          switch (code) {
            case XMLStreamConstants.START_ELEMENT: // START_ELEMENT:
              currentElement = reader.getLocalName();
              break;
            case XMLStreamConstants.CHARACTERS: // CHARACTERS:
              if (currentElement.equalsIgnoreCase("uid")) {
                propertyName += reader.getText().trim();
                System.out.println(propertyName);
              } else if (currentElement.equalsIgnoreCase("location")) {
                propertyValue += reader.getText().trim();
                System.out.println(propertyValue);

              } else if (currentElement.equalsIgnoreCase("age")) {
                propertyValue += ("," + reader.getText().trim());
                System.out.println(propertyValue);
              }
              break;
          }
        }
        reader.close();
        context.write(new Text(propertyName.trim()), new Text(propertyValue.trim()));

      } catch (Exception e) {
        throw new IOException(e);
      }
    }
Пример #4
0
 static {
   ClassLoader classLoader = APIServlet.class.getClassLoader();
   try (InputStream is = APIServlet.class.getResourceAsStream("endpoints.xml")) {
     assert is != null : "endpoints.xml is missing";
     XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(is);
     try {
       reader.nextTag();
       reader.require(XMLStreamConstants.START_ELEMENT, null, "endpoints");
       readEndpoint(reader, ROOT, classLoader);
       reader.require(XMLStreamConstants.END_ELEMENT, null, "endpoints");
     } catch (XMLStreamException e) {
       Location l = reader.getLocation();
       LOG.warn(
           "Error reading endpoints.xml [" + l.getLineNumber() + ", " + l.getColumnNumber() + ']',
           e);
     } finally {
       reader.close();
     }
   } catch (IOException | XMLStreamException e) {
     LOG.warn("Error reading endpoints.xml", e);
   }
 }