summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c34b990)
raw | patch | inline | side by side (parent: c34b990)
author | mental <mental@users.sourceforge.net> | |
Thu, 25 Jan 2007 04:07:20 +0000 (04:07 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Thu, 25 Jan 2007 04:07:20 +0000 (04:07 +0000) |
src/xml/repr-io.cpp | patch | blob | history | |
src/xml/repr.cpp | patch | blob | history | |
src/xml/repr.h | patch | blob | history | |
src/xml/simple-document.h | patch | blob | history |
diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp
index a7425ccb3eaa9aeb274f67fee981413e720a71b6..c1d764a8b38ae9818dd5622c0cc1b30fab6da917 100644 (file)
--- a/src/xml/repr-io.cpp
+++ b/src/xml/repr-io.cpp
#include "xml/repr.h"
#include "xml/attribute-record.h"
+#include "xml/simple-document.h"
#include "io/sys.h"
#include "io/uristream.h"
using Inkscape::Util::List;
using Inkscape::Util::cons;
using Inkscape::XML::Document;
+using Inkscape::XML::SimpleDocument;
using Inkscape::XML::Node;
using Inkscape::XML::AttributeRecord;
static Document *sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns);
-static Node *sp_repr_svg_read_node (xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map);
+static Node *sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map);
static gint sp_repr_qualified_name (gchar *p, gint len, xmlNsPtr ns, const xmlChar *name, const gchar *default_ns, GHashTable *prefix_map);
static void sp_repr_write_stream_root_element (Node *repr, Writer &out, bool add_whitespace, gchar const *default_ns, int inlineattrs, int indent);
static void sp_repr_write_stream (Node *repr, Writer &out, gint indent_level, bool add_whitespace, Glib::QueryQuark elide_prefix, int inlineattrs, int indent);
GHashTable * prefix_map;
prefix_map = g_hash_table_new (g_str_hash, g_str_equal);
- GSList *reprs=NULL;
- Node *root=NULL;
+ Document *rdoc = new Inkscape::XML::SimpleDocument();
+ Node *root=NULL;
for ( node = doc->children ; node != NULL ; node = node->next ) {
if (node->type == XML_ELEMENT_NODE) {
- Node *repr=sp_repr_svg_read_node (node, default_ns, prefix_map);
- reprs = g_slist_append(reprs, repr);
+ Node *repr=sp_repr_svg_read_node(rdoc, node, default_ns, prefix_map);
+ rdoc->appendChild(repr);
+ Inkscape::GC::release(repr);
if (!root) {
root = repr;
break;
}
} else if ( node->type == XML_COMMENT_NODE ) {
- Node *comment=sp_repr_svg_read_node(node, default_ns, prefix_map);
- reprs = g_slist_append(reprs, comment);
+ Node *comment=sp_repr_svg_read_node(rdoc, node, default_ns, prefix_map);
+ rdoc->appendChild(comment);
+ Inkscape::GC::release(comment);
}
}
- Document *rdoc=NULL;
-
if (root != NULL) {
/* promote elements of SVG documents that don't use namespaces
* into the SVG namespace */
{
promote_to_svg_namespace(root);
}
-
- rdoc = sp_repr_document_new_list(reprs);
- }
-
- for ( GSList *iter = reprs ; iter ; iter = iter->next ) {
- Node *repr=(Node *)iter->data;
- Inkscape::GC::release(repr);
}
- g_slist_free(reprs);
g_hash_table_destroy (prefix_map);
@@ -437,7 +431,7 @@ sp_repr_qualified_name (gchar *p, gint len, xmlNsPtr ns, const xmlChar *name, co
}
static Node *
-sp_repr_svg_read_node (xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map)
+sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map)
{
Node *repr, *crepr;
xmlAttrPtr prop;
@@ -459,17 +453,16 @@ sp_repr_svg_read_node (xmlNodePtr node, const gchar *default_ns, GHashTable *pre
return NULL; // we do not preserve all-whitespace nodes unless we are asked to
}
- Node *rdoc = sp_repr_new_text((const gchar *)node->content);
- return rdoc;
+ return xml_doc->createTextNode((const gchar *)node->content);
}
if (node->type == XML_COMMENT_NODE)
- return sp_repr_new_comment((const gchar *)node->content);
+ return xml_doc->createComment((const gchar *)node->content);
if (node->type == XML_ENTITY_DECL) return NULL;
sp_repr_qualified_name (c, 256, node->ns, node->name, default_ns, prefix_map);
- repr = sp_repr_new (c);
+ repr = xml_doc->createElement(c);
/* TODO remember node->ns->prefix if node->ns != NULL */
for (prop = node->properties; prop != NULL; prop = prop->next) {
@@ -485,7 +478,7 @@ sp_repr_svg_read_node (xmlNodePtr node, const gchar *default_ns, GHashTable *pre
child = node->xmlChildrenNode;
for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
- crepr = sp_repr_svg_read_node (child, default_ns, prefix_map);
+ crepr = sp_repr_svg_read_node (xml_doc, child, default_ns, prefix_map);
if (crepr) {
repr->appendChild(crepr);
Inkscape::GC::release(crepr);
diff --git a/src/xml/repr.cpp b/src/xml/repr.cpp
index bd64afc34eb5252111f8bee9216afcdaca6a8bca..c6943a2525291f6d059ccf8f5f8d6e822e90a8d0 100644 (file)
--- a/src/xml/repr.cpp
+++ b/src/xml/repr.cpp
Inkscape::XML::Document *
sp_repr_document_new(char const *rootname)
{
- Inkscape::XML::Document *doc = new Inkscape::XML::SimpleDocument(g_quark_from_static_string("xml"));
+ Inkscape::XML::Document *doc = new Inkscape::XML::SimpleDocument();
if (!strcmp(rootname, "svg:svg")) {
doc->setAttribute("version", "1.0");
doc->setAttribute("standalone", "no");
return doc;
}
-/// Returns new document having reprs as first child.
-Inkscape::XML::Document *
-sp_repr_document_new_list(GSList *reprs)
-{
- g_assert(reprs != NULL);
-
- Inkscape::XML::Document *doc = sp_repr_document_new("void");
- doc->removeChild(doc->firstChild());
-
- for ( GSList *iter = reprs ; iter ; iter = iter->next ) {
- Inkscape::XML::Node *repr = (Inkscape::XML::Node *) iter->data;
- doc->appendChild(repr);
- }
-
- g_assert(sp_repr_document_root(doc) != NULL);
-
- return doc;
-}
-
/*
Local Variables:
mode:c++
diff --git a/src/xml/repr.h b/src/xml/repr.h
index ac7ca3218c28d6be2025aae9aa4e1d1868b6f898..416c979f90d675df04ff933830dd4aadbba8cf32 100644 (file)
--- a/src/xml/repr.h
+++ b/src/xml/repr.h
gchar const *value);
-Inkscape::XML::Document *sp_repr_document_new_list(GSList *reprs);
-
inline Inkscape::XML::Node *sp_repr_document_first_child(Inkscape::XML::Document const *doc) {
return const_cast<Inkscape::XML::Node *>(doc->firstChild());
}
index c8ee4d9b4812befa5904d5944d1289097c702723..11d0ef4a246e6ffb6e55ffbc079b9777a3ce0752 100644 (file)
public NodeObserver
{
public:
- explicit SimpleDocument(int code)
- : SimpleNode(code), _in_transaction(false)
+ explicit SimpleDocument()
+ : SimpleNode(g_quark_from_static_string("xml")), _in_transaction(false)
{
_initBindings();
}