XML DOM解析错误

时间:2016-01-02 17:40:39

标签: java xml nodes domparser

我有XML文档。我试图连接两个字段。以下是我的代码。请检讨一下。我坚持产出一代,请帮忙 -

public class conc extends AbstractTransformation {

  public void transform(TransformationInput input, TransformationOutput output)
    throws StreamTransformationException {

    String RESULT = new String();

   InputStream in = input.getInputPayload().getInputStream();
   OutputStream out = output.getOutputPayload().getOutputStream();

    try {
        //Create DOM parser
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);

        NodeList n1 = doc.getElementsByTagName("Emp_Name");
        NodeList n2 = doc.getElementsByTagName("Emp_Surname");
        String nv1 = doc.getNodeName();
        String nv2 = doc.getNodeName();
        if (nv1.equals(n1) && nv2.equals(n2))
            RESULT = nv1.concat(nv2);


   // Create output DOM document.  
      Document outDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

      String document_exit = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"  +
    "<ns0:MT_RJava_Concate xmlns:ns0=urn:javaMapping.com/Rashmi>" +
        "<Records> <EmployeeID/> <RESULT>" + RESULT + "</RESULT> </Records>";

   // Write DOM document to outputStream.
        TransformerFactory.newInstance().newTransformer().transform(new DOMSource(outDoc), new StreamResult(out));

    }catch (Exception exception) {
        getTrace().addDebugMessage(exception.getMessage());
        throw new StreamTransformationException(exception.toString());
    }
  }
}

0 个答案:

没有答案