浏览代码

print_xml

David Rose 14 年之前
父节点
当前提交
bbdd1341d8
共有 2 个文件被更改,包括 31 次插入0 次删除
  1. 28 0
      panda/src/dxml/config_dxml.cxx
  2. 3 0
      panda/src/dxml/config_dxml.h

+ 28 - 0
panda/src/dxml/config_dxml.cxx

@@ -14,6 +14,7 @@
 
 #include "config_dxml.h"
 #include "dconfig.h"
+#include <stdio.h>
 
 BEGIN_PUBLISH
 #include "tinyxml.h"
@@ -72,3 +73,30 @@ write_xml_stream(ostream &out, TiXmlDocument *doc) {
   out << *doc;
 }
 END_PUBLISH
+
+BEGIN_PUBLISH
+////////////////////////////////////////////////////////////////////
+//     Function: print_xml
+//  Description: Writes an XML object to stdout, with formatting.
+////////////////////////////////////////////////////////////////////
+void
+print_xml(TiXmlNode *xnode) {
+  xnode->Print(stdout, 0);
+}
+END_PUBLISH
+
+BEGIN_PUBLISH
+////////////////////////////////////////////////////////////////////
+//     Function: print_xml_to_file
+//  Description: Writes an XML object to the indicated file, with
+//               formatting.  Unfortunately the VFS cannot be
+//               supported; the file must be a real filename on disk.
+////////////////////////////////////////////////////////////////////
+void
+print_xml_to_file(const Filename &filename, TiXmlNode *xnode) {
+  string os_name = filename.to_os_specific();
+  FILE *file = fopen(os_name.c_str(), "w");
+  xnode->Print(file, 0);
+  fclose(file);
+}
+END_PUBLISH

+ 3 - 0
panda/src/dxml/config_dxml.h

@@ -34,9 +34,12 @@ NotifyCategoryDecl(dxml, EXPCL_PANDA, EXPTP_PANDA);
 extern EXPCL_PANDA void init_libdxml();
 
 class TiXmlDocument;
+class TiXmlNode;
 BEGIN_PUBLISH
 TiXmlDocument *read_xml_stream(istream &in);
 void write_xml_stream(ostream &out, TiXmlDocument *doc);
+void print_xml(TiXmlNode *xnode);
+void print_xml_to_file(const Filename &filename, TiXmlNode *xnode);
 END_PUBLISH
 
 #endif