- Timestamp:
- 2008-08-25T12:32:17+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gli/trunk/src/org/greenstone/gatherer/util/XMLTools.java
r16331 r16988 624 624 f.setLineWidth (0); // Why isn't this working! 625 625 f.setPreserveSpace (false); 626 627 f.setNonEscapingElements (nonEscapingTagNames); 626 if (nonEscapingTagNames != null) { 627 f.setNonEscapingElements (nonEscapingTagNames); 628 } 628 629 // Create the necessary writer stream for serialization. 629 630 OutputStreamWriter osw = new OutputStreamWriter (os, "UTF-8"); … … 644 645 /** Write an XML document to a given file */ 645 646 static public void writeXMLFile (File xml_file, Document document) { 646 try { 647 OutputStream os = new FileOutputStream (xml_file); 648 // Create an output format for our document. 649 OutputFormat f = new OutputFormat (document); 650 f.setEncoding ("UTF-8"); 651 f.setIndenting (true); 652 f.setLineWidth (0); // Why isn't this working! 653 f.setPreserveSpace (false); 654 // Create the necessary writer stream for serialization. 655 OutputStreamWriter osw = new OutputStreamWriter (os, "UTF-8"); 656 Writer w = new BufferedWriter (osw); 657 // Generate a new serializer from the above. 658 XMLSerializer s = new XMLSerializer (w, f); 659 s.asDOMSerializer (); 660 // Finally serialize the document to file. 661 s.serialize (document); 662 // And close. 663 os.close (); 664 } 665 catch (Exception exception) { 666 DebugStream.printStackTrace (exception); 667 } 668 } 669 647 writeXMLFile(xml_file, document, null); 648 } 649 670 650 public static void printXMLNode (Node e) { 671 651 printXMLNode (e, 0) ; … … 770 750 771 751 } 752 753 public static String xmlNodeToStringWithoutIndenting (Node e) { 754 StringBuffer sb = new StringBuffer (""); 755 xmlNodeToStringWithoutNewline(sb, e, -1); 756 return sb.toString(); 757 } 772 758 public static String xmlNodeToStringWithoutNewline (Node e){ 773 759 StringBuffer sb = new StringBuffer (""); … … 780 766 for (int i=0 ; i<depth ; i++) 781 767 sb.append (' ') ; 782 768 783 769 if (e.getNodeType () == Node.TEXT_NODE){ 784 770 if (e.getNodeValue () != "") { … … 811 797 int len = children.getLength (); 812 798 for (int i = 0; i < len; i++) { 799 if (depth >= 0) { 813 800 xmlNodeToStringWithoutNewline (sb,children.item (i), depth + 1); 801 } else { 802 xmlNodeToStringWithoutNewline (sb,children.item (i), depth); 803 } 814 804 } 815 805
Note:
See TracChangeset
for help on using the changeset viewer.