diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-08-09 15:04:40 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-08-09 15:04:40 +0200 |
commit | e8e3ce68f3ea3ccbfaaa9a189b46676b91261a65 (patch) | |
tree | 1cc46a3b55cc8bc888e5e570be1d233576ea7fe9 | |
parent | 5dcf6aec988a09c8c0490ff2af2070acfb30b659 (diff) |
Add support for DOCTYPE declarationxhtml
-rw-r--r-- | xml/details/genx/genx.c | 52 | ||||
-rw-r--r-- | xml/details/genx/genx.h | 13 | ||||
-rw-r--r-- | xml/serializer | 9 | ||||
-rw-r--r-- | xml/serializer.cxx | 15 |
4 files changed, 89 insertions, 0 deletions
diff --git a/xml/details/genx/genx.c b/xml/details/genx/genx.c index e9b4686..1f2303d 100644 --- a/xml/details/genx/genx.c +++ b/xml/details/genx/genx.c @@ -2143,6 +2143,58 @@ genxStatus genxXmlDeclaration(genxWriter w, return GENX_SUCCESS; } +genxStatus genxDoctypeDeclaration(genxWriter w, + constUtf8 re, + constUtf8 pi, + constUtf8 si, + constUtf8 is) +{ + if (w->sequence != SEQUENCE_PRE_DOC) + return w->status = GENX_SEQUENCE_ERROR; + + if ((w->status = genxCheckText(w, re)) != GENX_SUCCESS) + return w->status; + + if (pi != NULL && (w->status = genxCheckText(w, pi)) != GENX_SUCCESS) + return w->status; + + if (si != NULL && (w->status = genxCheckText(w, si)) != GENX_SUCCESS) + return w->status; + + if (is != NULL && (w->status = genxCheckText(w, is)) != GENX_SUCCESS) + return w->status; + + SendCheck (w, "<!DOCTYPE "); + SendCheck (w, re); + + if (pi != NULL) + { + SendCheck (w, " PUBLIC\n \""); + SendCheck (w, pi); + SendCheck (w, "\""); + } + + if (si != NULL) + { + if (pi == NULL) + SendCheck (w, " SYSTEM"); + + SendCheck (w, "\n \""); + SendCheck (w, si); + SendCheck (w, "\""); + } + + if (is != NULL) + { + SendCheck (w, " [\n"); + SendCheck (w, is); + SendCheck (w, "\n]"); + } + + SendCheck (w, ">\n"); + return GENX_SUCCESS; +} + genxStatus genxComment(genxWriter w, constUtf8 text) { size_t i; diff --git a/xml/details/genx/genx.h b/xml/details/genx/genx.h index bdaeee1..e55b467 100644 --- a/xml/details/genx/genx.h +++ b/xml/details/genx/genx.h @@ -205,6 +205,19 @@ genxStatus genxXmlDeclaration(genxWriter w, constUtf8 encoding, constUtf8 standalone); /* + * Write DOCTYPE declaration. If public_id is not NULL, then this is + * a PUBLIC DOCTYPE declaration, otherwise, if system_id is not NULL, + * then this is a SYSTEM DOCTYPE. If both are NULL, then a DOCTYPE + * that only contains the root element and, if not NULL, internal + * subset is written. + */ +genxStatus genxDoctypeDeclaration(genxWriter w, + constUtf8 root_element, + constUtf8 public_id, + constUtf8 system_id, + constUtf8 internal_subset); + +/* * Write a comment */ genxStatus genxComment(genxWriter w, constUtf8 text); diff --git a/xml/serializer b/xml/serializer index 6c55d51..68e72c3 100644 --- a/xml/serializer +++ b/xml/serializer @@ -196,6 +196,15 @@ namespace xml const std::string& encoding = "UTF-8", const std::string& standalone = ""); + // DOCTYPE declaration. If encoding or standalone are not specified, + // then these attributes are omitted from the output. + // + void + doctype_decl (const std::string& root_element, + const std::string& public_id = "", + const std::string& system_id = "", + const std::string& internal_subset = ""); + // Utility functions. // public: diff --git a/xml/serializer.cxx b/xml/serializer.cxx index 4d1da5b..775105f 100644 --- a/xml/serializer.cxx +++ b/xml/serializer.cxx @@ -241,6 +241,21 @@ namespace xml handle_error (e); } + void serializer:: + doctype_decl (const string& re, + const string& pi, + const string& si, + const string& is) + { + if (genxStatus e = genxDoctypeDeclaration ( + s_, + reinterpret_cast<constUtf8> (re.c_str ()), + (pi.empty () ? 0 : reinterpret_cast<constUtf8> (pi.c_str ())), + (si.empty () ? 0 : reinterpret_cast<constUtf8> (si.c_str ())), + (is.empty () ? 0 : reinterpret_cast<constUtf8> (is.c_str ())))) + handle_error (e); + } + bool serializer:: lookup_namespace_prefix (const string& ns, string& p) { |