Social Icons

.

суббота, 8 мая 2010 г.

JSE: String to XML

 


public static Document parseXml(String szMessage){
 Document theDocument = null;
 try{
  DocumentBuilderFactory theFactory = DocumentBuilderFactory.newInstance();
  theFactory.setValidating(false);
  theFactory.setNamespaceAware(false);
  DocumentBuilder theBuilder = theFactory.newDocumentBuilder();

  ByteArrayInputStream theStream = new ByteArrayInputStream( szMessage.getBytes() );
  theDocument = theBuilder.parse(theStream);

  if( theDocument == null) throw new Exception("theDocument == null");
  if( theDocument.getDocumentElement() == null) throw new Exception("theDocument.getDocumentElement() == null");
 }
 catch(Exception ex){
  System.out.println("Can't transform message to XML document. " + ex.getMessage() );
  theDocument = null;
 }
 
 return theDocument;
}


 

Комментариев нет:

Отправить комментарий

 

Так говорил Учитель:

У хорошо написанной программы есть свой собственный рай, у плохо написанной — свой собственный ад.

Russian Developer

Взгляд его светел, усилия праведны, старания бесплодны, дело безнадежно ...