Ejemplo n.º 1
0
  public String AsXml() {
    XmlOptions opt = (new XmlOptions()).setSavePrettyPrint();
    opt.setSaveSuggestedPrefixes(Utilities.SuggestedNamespaces());
    opt.setSaveNamespacesFirst();
    opt.setSaveAggressiveNamespaces();
    opt.setUseDefaultNamespace();

    DescribeSRSResponseDocument document = completeResponse();

    ArrayList errorList = new ArrayList();
    opt.setErrorListener(errorList);
    boolean isValid = document.validate(opt);

    // If the XML isn't valid, loop through the listener's contents,
    // printing contained messages.
    if (!isValid) {
      for (int i = 0; i < errorList.size(); i++) {
        XmlError error = (XmlError) errorList.get(i);

        System.out.println("\n");
        System.out.println("Message: " + error.getMessage() + "\n");
        System.out.println(
            "Location of invalid XML: " + error.getCursorLocation().xmlText() + "\n");
      }
    }
    return document.xmlText(opt);
  }
Ejemplo n.º 2
0
  @Test
  public void validFullResponse() {
    XmlOptions opt = (new XmlOptions()).setSavePrettyPrint();
    opt.setSaveSuggestedPrefixes(Utilities.SuggestedNamespaces());
    opt.setSaveNamespacesFirst();
    opt.setSaveAggressiveNamespaces();
    opt.setUseDefaultNamespace();

    XmlObject co = completeResponse();
    ArrayList errorList = new ArrayList();
    boolean validXml = Utilities.validateXml(opt, co, errorList);
    assertTrue(errorList.toString(), validXml);
  }