From bbdd1341d856cbc9d08622017685b0e57f0fdc80 Mon Sep 17 00:00:00 2001 From: David Rose Date: Sun, 1 Jan 2012 02:39:36 +0000 Subject: [PATCH] print_xml --- panda/src/dxml/config_dxml.cxx | 28 ++++++++++++++++++++++++++++ panda/src/dxml/config_dxml.h | 3 +++ 2 files changed, 31 insertions(+) diff --git a/panda/src/dxml/config_dxml.cxx b/panda/src/dxml/config_dxml.cxx index 3a5adb2dc2..077e79b275 100755 --- a/panda/src/dxml/config_dxml.cxx +++ b/panda/src/dxml/config_dxml.cxx @@ -14,6 +14,7 @@ #include "config_dxml.h" #include "dconfig.h" +#include 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 diff --git a/panda/src/dxml/config_dxml.h b/panda/src/dxml/config_dxml.h index f88c98dcc2..5e78df63a6 100755 --- a/panda/src/dxml/config_dxml.h +++ b/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