1 31 package org.pdfbox.util; 32 33 import java.io.InputStream ; 34 import java.io.IOException ; 35 36 import javax.xml.parsers.DocumentBuilder ; 37 import javax.xml.parsers.DocumentBuilderFactory ; 38 39 import org.w3c.dom.Document ; 40 import org.w3c.dom.Element ; 41 import org.w3c.dom.Node ; 42 import org.w3c.dom.NodeList ; 43 import org.w3c.dom.Text ; 44 45 51 public class XMLUtil 52 { 53 57 private XMLUtil() 58 { 59 } 60 61 68 public static Document parse( InputStream is ) throws IOException 69 { 70 try 71 { 72 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); 73 DocumentBuilder builder = builderFactory.newDocumentBuilder(); 74 return builder.parse( is ); 75 } 76 catch( Exception e ) 77 { 78 IOException thrown = new IOException ( e.getMessage() ); 79 throw thrown; 80 } 81 } 82 83 89 public static String getNodeValue( Element node ) 90 { 91 String retval = ""; 92 NodeList children = node.getChildNodes(); 93 for( int i=0; i<children.getLength(); i++ ) 94 { 95 Node next = children.item( i ); 96 if( next instanceof Text ) 97 { 98 retval = next.getNodeValue(); 99 } 100 } 101 return retval; 102 } 103 } 104 | Popular Tags |