toString字符串转换element文件格式

package com.ultrapower.service;


import java.io.IOException;

import java.io.Reader;

import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.xml.sax.InputSource;

import org.xml.sax.SAXException;


public class POCUtil

{
 public static Element[] transStringToW3cElement(String xmlString)
 
 {
  Element[] elems = new Element[1];
  elems[0] = getElementByString(xmlString);
  return elems;
 }

 
 public static Element[] returnValidateInfo(int faultType,
         String errorMessage)
 {
  return transStringToW3cElement("-1"
          + errorMessage + "
");
  }

 
 private static Element getElementByString(String xmlString)
 
 {
  if (xmlString == null)
   xmlString = "-999undefined error";
  Document doc = null;
  try
  {
   Reader strreader = new StringReader(xmlString);
   DocumentBuilder builder = DocumentBuilderFactory
           .newInstance().newDocumentBuilder();
   doc = builder.parse(new InputSource(strreader));
   } catch (ParserConfigurationException e)
  {
   e.printStackTrace();
   } catch (SAXException e)
  {
   e.printStackTrace();
   } catch (IOException e)
  {
   e.printStackTrace();
   } catch (Exception e)
  {
   e.printStackTrace();
   }
 
  return doc.getDocumentElement();
  }

 
 public static void main(String[] args)
 
 {
  }
 
}

 

你可能感兴趣的:(接口)