- Timestamp:
- 2014-04-24T21:34:33+12:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java
r26354 r28995 22 22 23 23 // JAXP 24 import javax.xml.parsers.DocumentBuilder; 25 import javax.xml.parsers.DocumentBuilderFactory; 24 26 import javax.xml.parsers.FactoryConfigurationError; 25 27 import javax.xml.parsers.ParserConfigurationException; 26 28 import javax.xml.parsers.SAXParser; 27 29 import javax.xml.parsers.SAXParserFactory; 30 28 31 29 32 /** This class is a static class containing useful XML functions */ … … 331 334 static final private String HEADER = "<?xml version='1.0' encoding='UTF-8'?><collectionConfig xmlns:gsf='http://www.greenstone.org/greenstone3/schema/ConfigFormat' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"; 332 335 static final private String FOOTER = "</collectionConfig>"; 336 337 338 public static Document getDOM(String xml_str) 339 { 340 Document doc = null; 341 try { 342 /*SAXParserFactory factory = SAXParserFactory.newInstance(); 343 factory.setNamespaceAware(true); 344 //factory.setValidating (true); 345 SAXParser parser = factory.newSAXParser(); 346 InputSource iSource = new InputSource(new StringReader(xml_str)); 347 // parser.parse (iSource, new DefaultHandler ()); 348 349 org.xml.sax.XMLReader reader = parser.getXMLReader(); 350 reader.setContentHandler(new DefaultHandler()); 351 reader.setErrorHandler(new DefaultHandler()); 352 doc = reader.parse(iSource); 353 */ 354 355 DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 356 InputSource is = new InputSource(); 357 is.setCharacterStream(new StringReader(xml_str)); 358 doc = db.parse(is); 359 360 } catch (Exception e) { 361 e.printStackTrace(); 362 } 363 return doc; 364 } 333 365 334 366 public static String parse(String xml_str) … … 991 1023 public static void xmlNodeToString(StringBuffer sb, Node e, boolean indent, String indentString, int depth) 992 1024 { 993 if (e.getNodeType() == Node.TEXT_NODE) 1025 1026 if (e.getNodeType() == Node.CDATA_SECTION_NODE) 1027 { 1028 if (e.getNodeValue() != "") 1029 { 1030 String text = e.getNodeValue(); 1031 sb.append("<![CDATA["); 1032 sb.append(text); 1033 sb.append("]]>"); 1034 } 1035 return; 1036 } 1037 1038 if (e.getNodeType() == Node.TEXT_NODE) 994 1039 { 995 1040 if (e.getNodeValue() != "") … … 1057 1102 hasElements = true; 1058 1103 } 1059 if ( children.item(i).getNodeType() == Node.TEXT_NODE&& indent)1104 if ((children.item(i).getNodeType() == Node.TEXT_NODE || children.item(i).getNodeType() == Node.CDATA_SECTION_NODE) && indent) 1060 1105 { 1061 1106 if (children.item(i).getNodeValue().trim().length() > 0)
Note:
See TracChangeset
for help on using the changeset viewer.