- Timestamp:
- 2016-08-12T19:47:27+12:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java
r29730 r30701 13 13 import java.io.IOException; 14 14 import java.io.StringReader; 15 import java.io.StringWriter; // for elementToString() 15 16 16 17 // SAX … … 28 29 import javax.xml.parsers.SAXParser; 29 30 import javax.xml.parsers.SAXParserFactory; 31 // for elementToString(): 32 import javax.xml.transform.OutputKeys; 33 import javax.xml.transform.Transformer; 34 import javax.xml.transform.TransformerFactory; 35 import javax.xml.transform.dom.DOMSource; 36 import javax.xml.transform.stream.StreamResult; 30 37 31 38 … … 523 530 if (xml_file.exists() == false) 524 531 { 532 System.err.println("@@@ file " + xml_file + " does not exist."); 525 533 return null; 526 534 } … … 1224 1232 } 1225 1233 } 1234 1235 1236 1237 // This method will convert an Element to a String too, like xmlNodeToString() above. 1238 // But for a document root element (doc.getDocumentElement()), this method will additionally 1239 // return its processing instruction line at the start (<?xml ... ?>). 1240 // This method copied into GLI from src/java/org/greenstone/gsdl3/util/GSXML.java 1241 public static String elementToString(Element e, boolean indent) 1242 { 1243 String str = ""; 1244 try 1245 { 1246 TransformerFactory tf = TransformerFactory.newInstance(); 1247 Transformer trans = tf.newTransformer(); 1248 StringWriter sw = new StringWriter(); 1249 if (indent) 1250 { 1251 trans.setOutputProperty(OutputKeys.INDENT, "yes"); 1252 } 1253 else 1254 { 1255 trans.setOutputProperty(OutputKeys.INDENT, "no"); 1256 } 1257 trans.transform(new DOMSource(e), new StreamResult(sw)); 1258 str += sw.toString(); 1259 } 1260 catch (Exception ex) 1261 { 1262 str += "Exception: couldn't write " + e + " to log"; 1263 } 1264 finally 1265 { 1266 return str; 1267 } 1268 } 1226 1269 }
Note:
See TracChangeset
for help on using the changeset viewer.