summaryrefslogtreecommitdiff
path: root/ACEXML
diff options
context:
space:
mode:
authorkitty <kitty@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-06-24 08:42:35 +0000
committerkitty <kitty@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-06-24 08:42:35 +0000
commit36a5a3e8f48ec265bca4a18673eebf5043586d61 (patch)
treed66d13bb6e29e53eff73a02552399ecfa9d5214c /ACEXML
parent55035a3f42ff5f6d08ccacc270b93c7c8cf35a5b (diff)
downloadATCD-36a5a3e8f48ec265bca4a18673eebf5043586d61.tar.gz
ChangeLogTag: Mon Jun 24 03:26:10 2002 Krishnakumar B <kitty@cs.wustl.edu>
Diffstat (limited to 'ACEXML')
-rw-r--r--ACEXML/common/AttributesImpl.cpp33
-rw-r--r--ACEXML/common/AttributesImpl.h29
-rw-r--r--ACEXML/common/AttributesImpl.i10
-rw-r--r--ACEXML/common/NamespaceSupport.cpp41
-rw-r--r--ACEXML/examples/SAXPrint/Print_Handler.cpp9
-rw-r--r--ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp14
-rw-r--r--ACEXML/examples/SAXPrint/ns.svc.conf.xml4
-rw-r--r--ACEXML/parser/parser/Parser.cpp208
-rw-r--r--ACEXML/parser/parser/Parser.h26
9 files changed, 268 insertions, 106 deletions
diff --git a/ACEXML/common/AttributesImpl.cpp b/ACEXML/common/AttributesImpl.cpp
index e010dd49cc9..95eb4c2742b 100644
--- a/ACEXML/common/AttributesImpl.cpp
+++ b/ACEXML/common/AttributesImpl.cpp
@@ -32,11 +32,9 @@ ACEXML_AttributesImpl::addAttribute (const ACEXML_Char *uri,
const ACEXML_Char *type,
const ACEXML_Char *value)
{
- // @@ How do I check for the name here? Which name should
- // I use to check for duplication?
-
+ if (this->isDuplicate (uri, localName, qName))
+ return -1;
int length = this->attrs_.size ();
-
this->attrs_.size (length+1);
this->setAttribute (length,
uri,
@@ -50,17 +48,36 @@ ACEXML_AttributesImpl::addAttribute (const ACEXML_Char *uri,
int
ACEXML_AttributesImpl::addAttribute (const ACEXML_Attribute &att)
{
- // @@ How do I check for the name here? Which name should
- // I use to check for duplication?
-
+ if (this->isDuplicate (att.uri(), att.localName(), att.qName()))
+ return -1;
int length = this->attrs_.size ();
-
this->attrs_.size (length+1);
this->attrs_[length] = att;
return length;
}
int
+ACEXML_AttributesImpl::isDuplicate (const ACEXML_Char *uri,
+ const ACEXML_Char *localName,
+ const ACEXML_Char *qName)
+{
+ for (size_t i = 0; i < this->attrs_.size(); ++i)
+ {
+ if (ACE_OS::strcmp (this->attrs_[i].localName(), localName) == 0)
+ {
+ if (qName != 0 && this->attrs_[i].qName() != 0
+ && ACE_OS::strcmp (this->attrs_[i].qName(), qName) == 0)
+ {
+ if (uri != 0 && this->attrs_[i].uri() != 0
+ && ACE_OS::strcmp (this->attrs_[i].uri(), uri) == 0)
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
+int
ACEXML_AttributesImpl::removeAttribute (size_t index)
{
size_t length = this->attrs_.size ();
diff --git a/ACEXML/common/AttributesImpl.h b/ACEXML/common/AttributesImpl.h
index 555d7d38b53..5339ac22bdf 100644
--- a/ACEXML/common/AttributesImpl.h
+++ b/ACEXML/common/AttributesImpl.h
@@ -58,34 +58,34 @@ public:
const ACEXML_Char *type,
const ACEXML_Char *value);
- /// Set \a uri_.
+ /// Get \a uri_.
const ACEXML_Char *uri (void) const;
- /// Get \a uri_.
+ /// Set \a uri_.
void uri (const ACEXML_Char *uri);
- /// Set \a localName_.
+ /// Get \a localName_.
const ACEXML_Char *localName (void) const;
- /// Get \a localName_.
+ /// Set \a localName_.
void localName (const ACEXML_Char *localName);
- /// Set \a qName_.
+ /// Get \a qName_.
const ACEXML_Char *qName (void) const;
- /// Get \a qName_.
+ /// Set \a qName_.
void qName (const ACEXML_Char *qName);
- /// Set \a type_.
+ /// Get \a type_.
const ACEXML_Char *type (void) const;
- /// Get \a type_.
+ /// Set \a type_.
void type (const ACEXML_Char *type);
- /// Set \a value_.
+ /// Get \a value_.
const ACEXML_Char *value (void) const;
- /// Get \a value_.
+ /// Set \a value_.
void value (const ACEXML_Char *value);
/// Assignment operator.
@@ -122,7 +122,8 @@ typedef ACE_Array<ACEXML_Attribute> ACEXML_Attribute_Array;
*
* There are two typical uses of this class:
*
- * - to take a persistent snapshot of an Attributes object in a startElement event; or
+ * - to take a persistent snapshot of an Attributes object in a
+ * startElement event; or
* - to construct or modify an Attributes object in a SAX2 driver or filter.
*
* This class replaces the now-deprecated SAX1 AttributeListImpl
@@ -156,6 +157,12 @@ public:
virtual int addAttribute (const ACEXML_Attribute &att);
/**
+ * Check for duplicate attributes.
+ */
+ virtual int isDuplicate (const ACEXML_Char *uri,
+ const ACEXML_Char *localName,
+ const ACEXML_Char *qName);
+ /**
* Remove an attribute from the array. Notice that this
* operation can invalidate previously acquired <index>
* value. (It will repack the array.)
diff --git a/ACEXML/common/AttributesImpl.i b/ACEXML/common/AttributesImpl.i
index f3510c1f07f..87a905b3304 100644
--- a/ACEXML/common/AttributesImpl.i
+++ b/ACEXML/common/AttributesImpl.i
@@ -55,7 +55,7 @@ ACEXML_Attribute::uri (void) const
ACEXML_INLINE void
ACEXML_Attribute::uri (const ACEXML_Char *uri)
{
- delete this->uri_;
+ delete[] this->uri_;
this->uri_ = ACE::strnew (uri);
}
@@ -68,7 +68,7 @@ ACEXML_Attribute::localName (void) const
ACEXML_INLINE void
ACEXML_Attribute::localName (const ACEXML_Char *localName)
{
- delete this->localName_;
+ delete[] this->localName_;
this->localName_ = ACE::strnew (localName);
}
@@ -81,7 +81,7 @@ ACEXML_Attribute::qName (void) const
ACEXML_INLINE void
ACEXML_Attribute::qName (const ACEXML_Char *qName)
{
- delete this->qName_;
+ delete[] this->qName_;
this->qName_ = ACE::strnew (qName);
}
@@ -94,7 +94,7 @@ ACEXML_Attribute::type (void) const
ACEXML_INLINE void
ACEXML_Attribute::type (const ACEXML_Char *type)
{
- delete this->type_;
+ delete[] this->type_;
this->type_ = ACE::strnew (type);
}
@@ -107,7 +107,7 @@ ACEXML_Attribute::value (void) const
ACEXML_INLINE void
ACEXML_Attribute::value (const ACEXML_Char *value)
{
- delete this->value_;
+ delete[] this->value_;
this->value_ = ACE::strnew (value);
}
diff --git a/ACEXML/common/NamespaceSupport.cpp b/ACEXML/common/NamespaceSupport.cpp
index e6226ebace4..6a66ff122d0 100644
--- a/ACEXML/common/NamespaceSupport.cpp
+++ b/ACEXML/common/NamespaceSupport.cpp
@@ -13,10 +13,10 @@ static const ACEXML_Char ACEXML_DEFAULT_NS_PREFIX[] = {0};
static const ACEXML_Char ACEXML_TABOO_NS_PREFIX[] = {'x', 'm', 'l', 0};
static const ACEXML_Char ACEXML_XMLNS_URI_name[] = {
- 'h', 't', 't', 'p', ':', '/', '/',
- 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',
- 'X', 'M', 'L', '/', '1', '9', '9', '8', '/',
- 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', 0};
+ 'h', 't', 't', 'p', ':', '/', '/',
+ 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',
+ 'X', 'M', 'L', '/', '1', '9', '9', '8', '/',
+ 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', 0};
const ACEXML_Char *ACEXML_NamespaceSupport::XMLNS = ACEXML_XMLNS_URI_name;
#if !defined (__ACEXML_INLINE__)
@@ -90,7 +90,6 @@ ACEXML_NamespaceSupport::declarePrefix (const ACEXML_Char *prefix,
if (ACE_OS_String::strcmp (ACEXML_TABOO_NS_PREFIX, prefix) == 0)
return -1;
- // @@ No way to check new failure.
ACEXML_String ns_prefix (prefix, 0, 0);
ACEXML_String ns_uri (uri, 0, 0);
@@ -148,7 +147,7 @@ ACEXML_NamespaceSupport::getPrefixes (ACEXML_STR_LIST &prefixes) const
int
ACEXML_NamespaceSupport::getPrefixes (const ACEXML_Char *uri,
- ACEXML_STR_LIST &prefixes) const
+ ACEXML_STR_LIST &prefixes) const
{
ACEXML_NS_CONTEXT_ENTRY *entry;
@@ -189,12 +188,11 @@ int
ACEXML_NamespaceSupport::pushContext (void)
{
ACEXML_NS_CONTEXT *temp = this->effective_context_;
- this->ns_stack_.push (temp);
ACE_NEW_RETURN (this->effective_context_,
ACEXML_NS_CONTEXT (),
-1);
- // @@ Copy everything from the old context the the new one.
+ // @@ Copy everything from the old context to the new one.
ACEXML_NS_CONTEXT_ENTRY *entry;
for (ACEXML_NS_CONTEXT_ITER iter (*temp);
@@ -202,28 +200,25 @@ ACEXML_NamespaceSupport::pushContext (void)
iter.advance ())
this->effective_context_->bind (entry->ext_id_,
entry->int_id_);
-
+ this->ns_stack_.push (temp);
return 0;
}
int
ACEXML_NamespaceSupport::processName (const ACEXML_Char *qName,
- const ACEXML_Char *&uri,
- const ACEXML_Char *&name,
- int is_attribute) const
+ const ACEXML_Char *&uri,
+ const ACEXML_Char *&name,
+ int is_attribute) const
{
- // @@ Need to use different rules to resolve attributes.
- ACE_UNUSED_ARG (is_attribute);
-
int qlen = ACE_OS_String::strlen (qName);
int len = -1;
for (int i = 0; i < qlen; ++i)
- if (qName [i] == ':')
- {
- len = i;
- break;
- }
+ if (qName [i] == ':')
+ {
+ len = i;
+ break;
+ }
ACEXML_String prefix;
@@ -236,6 +231,12 @@ ACEXML_NamespaceSupport::processName (const ACEXML_Char *qName,
prefix.set (qName, len, 1);
name = qName + len + 1;
}
+
+ if (is_attribute && len == -1) {
+ uri = ACEXML_DEFAULT_NS_PREFIX;
+ return 0;
+ }
+
ACEXML_NS_CONTEXT_ENTRY *entry;
if (this->effective_context_->find (prefix, entry) == 0)
diff --git a/ACEXML/examples/SAXPrint/Print_Handler.cpp b/ACEXML/examples/SAXPrint/Print_Handler.cpp
index 9711ac6e9e1..2286fc0ca1e 100644
--- a/ACEXML/examples/SAXPrint/Print_Handler.cpp
+++ b/ACEXML/examples/SAXPrint/Print_Handler.cpp
@@ -151,12 +151,15 @@ ACEXML_Print_Handler::startElement (const ACEXML_Char *uri,
}
void
-ACEXML_Print_Handler::startPrefixMapping (const ACEXML_Char *,
- const ACEXML_Char *,
+ACEXML_Print_Handler::startPrefixMapping (const ACEXML_Char * prefix,
+ const ACEXML_Char * uri,
ACEXML_Env &)
// ACE_THROW_SPEC ((ACEXML_SAXException))
{
- // No-op.
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_LIB_TEXT ("* Event startPrefixMapping () ***************\n")));
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_LIB_TEXT ("Prefix = %s, URI = %s\n"), prefix, uri));
}
// *** Methods inherit from ACEXML_DTDHandler.
diff --git a/ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp b/ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp
index 694f30ea198..3f15cef4e80 100644
--- a/ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp
+++ b/ACEXML/examples/SAXPrint/SAXPrint_Handler.cpp
@@ -127,8 +127,8 @@ ACEXML_SAXPrint_Handler::startDocument (ACEXML_Env &xmlenv)
{
ACE_UNUSED_ARG (xmlenv);
-// ACE_DEBUG ((LM_DEBUG,
-// ACE_LIB_TEXT ("* Event startDocument () ***************\n")));
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_LIB_TEXT ("* Event startDocument () ***************\n")));
}
void
@@ -157,12 +157,16 @@ ACEXML_SAXPrint_Handler::startElement (const ACEXML_Char *,
}
void
-ACEXML_SAXPrint_Handler::startPrefixMapping (const ACEXML_Char *,
- const ACEXML_Char *,
+ACEXML_SAXPrint_Handler::startPrefixMapping (const ACEXML_Char * prefix,
+ const ACEXML_Char * uri,
ACEXML_Env &)
// ACE_THROW_SPEC ((ACEXML_SAXException))
{
- // No-op.
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_LIB_TEXT ("* Event startPrefixMapping () ***************\n")));
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_LIB_TEXT ("Prefix = %s, URI = %s\n"), prefix, uri));
+
}
// *** Methods inherited from ACEXML_DTDHandler.
diff --git a/ACEXML/examples/SAXPrint/ns.svc.conf.xml b/ACEXML/examples/SAXPrint/ns.svc.conf.xml
index a7487dc360f..db1821d7ac0 100644
--- a/ACEXML/examples/SAXPrint/ns.svc.conf.xml
+++ b/ACEXML/examples/SAXPrint/ns.svc.conf.xml
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
-<ace:ACE_Svc_Conf xmlns:ace="http://ace.doc.wustl.edu/svcconf">
+<ace:ACE_Svc_Conf xmlns="http://ace.doc.wustl.edu/svcconf" xmlns:ace="http://ace.doc.wustl.edu/svcconf">
<static id="ACE_Service_Manager">
<params>-d</params>
<params>-p 4911</params>
@@ -43,4 +43,4 @@ Do you &amp;expect something more?]]>
<!-- remove CCM_App -->
<remove id="Test_&amp;Task&#x65;bc"/>
-</ace:ACE_Svc_Conf> \ No newline at end of file
+</ace:ACE_Svc_Conf>
diff --git a/ACEXML/parser/parser/Parser.cpp b/ACEXML/parser/parser/Parser.cpp
index 4432f0b866b..1ceed61c971 100644
--- a/ACEXML/parser/parser/Parser.cpp
+++ b/ACEXML/parser/parser/Parser.cpp
@@ -8,7 +8,13 @@ static const ACEXML_Char default_attribute_type[] = {'C', 'D', 'A', 'T', 'A', 0}
static const ACEXML_Char empty_string[] = { 0 };
const ACEXML_Char
-ACEXML_Parser::simple_parsing_name_[] = { 'S', 'i', 'm', 'p', 'l', 'e', 0 };
+ACEXML_Parser::simple_parsing_feature_[] = { 'S', 'i', 'm', 'p', 'l', 'e', 0 };
+
+const ACEXML_Char
+ACEXML_Parser::namespaces_feature_[] = {'h', 't', 't', 'p', ':', '/', '/', 'x', 'm', 'l', '.', 'o', 'r', 'g', '/', 's', 'a', 'x', '/', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '/', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', 's', 0 };
+
+const ACEXML_Char
+ACEXML_Parser::namespace_prefixes_feature_[] = {'h', 't', 't', 'p', ':', '/', '/', 'x', 'm', 'l', '.', 'o', 'r', 'g', '/', 's', 'a', 'x', '/', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '/', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '-', 'p', 'r', 'e', 'f', 'i', 'x', 'e', 's', 0 };
#if !defined (__ACEXML_INLINE__)
# include "ACEXML/parser/parser/Parser.i"
@@ -22,9 +28,6 @@ ACEXML_Parser::simple_parsing_name_[] = { 'S', 'i', 'm', 'p', 'l', 'e', 0 };
processing instruction
x element contents
- Figure out how to handle namespace here:
- and when to invoke start/endPrefixMapping?
-
Make sure we are freezing the obstack in all cases.
***/
@@ -39,7 +42,9 @@ ACEXML_Parser::ACEXML_Parser (void)
dtd_system_ (0),
dtd_public_ (0),
locator_(),
- simple_parsing_ (0)
+ simple_parsing_ (0),
+ namespaces_(1),
+ namespace_prefixes_ (0)
{
}
@@ -53,8 +58,21 @@ ACEXML_Parser::getFeature (const ACEXML_Char *name,
// ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException,
// ACEXML_SAXNotSupportedException))
{
- if (ACE_OS_String::strcmp (name, ACEXML_Parser::simple_parsing_name_) == 0)
- return this->simple_parsing_;
+ if (ACE_OS_String::strcmp (name,
+ ACEXML_Parser::simple_parsing_feature_) == 0)
+ {
+ return this->simple_parsing_;
+ }
+ else if (ACE_OS_String::strcmp (name,
+ ACEXML_Parser::namespaces_feature_) == 0)
+ {
+ return this->namespaces_;
+ }
+ else if (ACE_OS_String::strcmp (name,
+ ACEXML_Parser::namespace_prefixes_feature_) == 0)
+ {
+ return this->namespace_prefixes_;
+ }
xmlenv.exception (new ACEXML_SAXNotRecognizedException ());
return -1;
@@ -80,10 +98,25 @@ ACEXML_Parser::setFeature (const ACEXML_Char *name,
// ACE_THROW_SPEC ((ACEXML_SAXNotRecognizedException,
// ACEXML_SAXNotSupportedException))
{
- if (ACE_OS_String::strcmp (name, ACEXML_Parser::simple_parsing_name_) == 0) {
- this->simple_parsing_ = (boolean_value == 0 ? 0 : 1);
- return;
- }
+ if (ACE_OS_String::strcmp (name,
+ ACEXML_Parser::simple_parsing_feature_) == 0)
+ {
+ this->simple_parsing_ = (boolean_value == 0 ? 0 : 1);
+ return;
+ }
+ else if (ACE_OS_String::strcmp (name,
+ ACEXML_Parser::namespaces_feature_) == 0)
+ {
+ this->namespaces_ = (boolean_value == 0 ? 0 : 1);
+ return;
+ }
+ else if (ACE_OS_String::strcmp (name,
+ ACEXML_Parser::namespace_prefixes_feature_) == 0)
+ {
+ this->namespace_prefixes_ = (boolean_value == 0 ? 0 : 1);
+ return;
+ }
+
xmlenv.exception (new ACEXML_SAXNotRecognizedException ());
return;
}
@@ -230,6 +263,7 @@ ACEXML_Parser::parse (ACEXML_InputSource *input,
(ACE_LIB_TEXT ("Unexpected EOF")));
xmlenv.exception (exception);
this->report_fatal_error(*exception, xmlenv);
+ return;
break;
default: // Root element begins
prolog_done = 1;
@@ -722,6 +756,14 @@ ACEXML_Parser::parse_element (int is_root, ACEXML_Env &xmlenv)
else
{
this->xml_namespace_.processName(startname, ns_uri, ns_lname, 0);
+ const ACEXML_Char* prefix = this->xml_namespace_.getPrefix (ns_uri);
+ if (this->namespaces_)
+ {
+ this->content_handler_->startPrefixMapping (prefix,
+ ns_uri,
+ xmlenv);
+ ACEXML_CHECK;
+ }
this->content_handler_->startElement (ns_uri,
ns_lname,
startname,
@@ -733,21 +775,36 @@ ACEXML_Parser::parse_element (int is_root, ACEXML_Env &xmlenv)
startname,
xmlenv);
ACEXML_CHECK;
+ if (this->namespaces_)
+ {
+ this->content_handler_->endPrefixMapping (prefix, xmlenv);
+ ACEXML_CHECK;
+ }
}
if (new_namespace != 0)
this->xml_namespace_.popContext ();
return;
case '>':
- this->xml_namespace_.processName (startname, ns_uri, ns_lname, 0);
- this->content_handler_->startElement (ns_uri,
- ns_lname,
- startname,
- &attributes,
- xmlenv);
- ACEXML_CHECK;
- start_element_done = 1;
- break;
+ {
+ this->xml_namespace_.processName (startname, ns_uri, ns_lname, 0);
+ const ACEXML_Char* prefix = this->xml_namespace_.getPrefix (ns_uri);
+ if (this->namespaces_)
+ {
+ this->content_handler_->startPrefixMapping (prefix,
+ ns_uri,
+ xmlenv);
+ ACEXML_CHECK;
+ }
+ this->content_handler_->startElement (ns_uri,
+ ns_lname,
+ startname,
+ &attributes,
+ xmlenv);
+ ACEXML_CHECK;
+ start_element_done = 1;
+ break;
+ }
default:
ACEXML_Char *attvalue = 0;
ACEXML_Char *attname = this->read_name (ch);
@@ -772,49 +829,96 @@ ACEXML_Parser::parse_element (int is_root, ACEXML_Env &xmlenv)
attname[3] == 'n' &&
attname[4] == 's')
{
- if (new_namespace == 0)
+ if (this->namespaces_)
{
- this->xml_namespace_.pushContext ();
- new_namespace = 1;
- }
-
- ACE_Tokenizer ns_att (attname);
- ns_att.delimiter_replace (':', 0);
- ACEXML_Char *xmlns_prefix, *ns_name;
+ if (new_namespace == 0)
+ {
+ this->xml_namespace_.pushContext ();
+ new_namespace = 1;
+ }
- xmlns_prefix = ns_att.next ();
- ns_name = ns_att.next ();
+ ACE_Tokenizer ns_att (attname);
+ ns_att.delimiter_replace (':', 0);
- // @@ xmlns_prefix is not used now.
- ACE_UNUSED_ARG (xmlns_prefix);
- if (ns_name == 0)
+ ACEXML_Char *xmlns_prefix, *ns_name;
+ xmlns_prefix = ns_att.next ();
+ ns_name = ns_att.next ();
+ if (ns_name == 0)
+ {
+ if (this->xml_namespace_.declarePrefix (empty_string,
+ attvalue) == -1)
+ {
+ ACE_NEW_NORETURN (exception,
+ ACEXML_SAXParseException
+ (ACE_LIB_TEXT ("Invalid namespace p ref ix")));
+ xmlenv.exception (exception);
+ this->report_fatal_error(*exception, xmlenv);
+ return;
+ }
+ }
+ else
+ {
+ if (this->xml_namespace_.declarePrefix (ns_name,
+ attvalue) == -1)
+ {
+ ACE_NEW_NORETURN (exception,
+ ACEXML_SAXParseException
+ (ACE_LIB_TEXT ("Duplicate namespace pr efix")));
+ xmlenv.exception (exception);
+ this->report_fatal_error(*exception, xmlenv);
+ return;
+ }
+ }
+ }
+ if (this->namespace_prefixes_)
{
- // @@ Check return value?
- this->xml_namespace_.declarePrefix (empty_string,
- attvalue);
+ // Namespace_prefixes_feature_ is required. So add the
+ // xmlns:foo to the list of attributes.
+ if (attributes.addAttribute (0,
+ 0,
+ attname,
+ default_attribute_type,
+ attvalue) == -1)
+ {
+ ACE_NEW_NORETURN (exception,
+ ACEXML_SAXParseException
+ (ACE_LIB_TEXT ("Duplicate attribute found")));
+ xmlenv.exception (exception);
+ this->report_fatal_error(*exception, xmlenv);
+ return;
+ }
}
- else
+ if (!this->namespaces_ && !this->namespace_prefixes_)
{
- // @@ Check return value?
- this->xml_namespace_.declarePrefix (ns_name,
- attvalue);
+ ACE_NEW_NORETURN (exception,
+ ACEXML_SAXParseException
+ (ACE_LIB_TEXT ("Both namespaces feature and namespace_prefixes feature are false. Illegal Mode")));
+ xmlenv.exception (exception);
+ this->report_fatal_error(*exception, xmlenv);
+ return;
}
}
else
{
const ACEXML_Char *uri, *lName;
this->xml_namespace_.processName (attname, uri, lName, 1);
-
- attributes.addAttribute (uri,
- lName,
- attname,
- default_attribute_type,
- attvalue);
+ if (attributes.addAttribute (uri,
+ lName,
+ attname,
+ default_attribute_type,
+ attvalue) == -1)
+ {
+ ACE_NEW_NORETURN (exception,
+ ACEXML_SAXParseException
+ (ACE_LIB_TEXT ("Duplicate attribute found")));
+ xmlenv.exception (exception);
+ this->report_fatal_error(*exception, xmlenv);
+ return;
+ }
}
break;
}
}
-
ACEXML_Char *cdata;
size_t cdata_length = 0;
@@ -911,7 +1015,12 @@ ACEXML_Parser::parse_element (int is_root, ACEXML_Env &xmlenv)
endname,
xmlenv);
ACEXML_CHECK;
-
+ if (this->namespaces_)
+ {
+ const ACEXML_Char* prefix = this->xml_namespace_.getPrefix (ns_uri);
+ this->content_handler_->endPrefixMapping (prefix, xmlenv);
+ ACEXML_CHECK;
+ }
if (new_namespace != 0)
this->xml_namespace_.popContext ();
return;
@@ -983,7 +1092,6 @@ ACEXML_Parser::parse_element (int is_root, ACEXML_Env &xmlenv)
}
}
}
-
}
int
@@ -1088,7 +1196,7 @@ const ACEXML_String *
ACEXML_Parser::parse_reference (void)
{
// @@ We'll use a temporary buffer here as the Obstack is most likely in
- // use when we are here. This put a limit on the max length of a
+ // use when we are here. This puts a limit on the max length of a
// reference.
ACEXML_Char ref[MAXPATHLEN];
diff --git a/ACEXML/parser/parser/Parser.h b/ACEXML/parser/parser/Parser.h
index fa8060f1be5..c1eb8680bd7 100644
--- a/ACEXML/parser/parser/Parser.h
+++ b/ACEXML/parser/parser/Parser.h
@@ -412,11 +412,31 @@ protected:
* @var simple_parsing_name_
*
* This constant string defines the name of "simple XML parsing"
- * feature. When this feature is enable, ACEXML parser is allowed
+ * feature. When this feature is enabled, ACEXML parser is allowed
* to parse a simple XML stream without mandated XML prolog
* and no DTD defintion.
*/
- static const ACEXML_Char simple_parsing_name_[];
+ static const ACEXML_Char simple_parsing_feature_[];
+
+ /**
+ * @var namespaces_feature_
+ *
+ * This constant string defines the SAX XML Namespace feature. When this
+ * feature is enabled, ACEXML parser allows access by namespace qualified
+ * names.
+ */
+ static const ACEXML_Char namespaces_feature_[];
+
+ /**
+ * @var namespace_prefixes_feature_
+ *
+ * This constant string defines the SAX XML Namespace prefixes feature.
+ * Normally the list of attributes returned by the parser will not
+ * contain attributes used as namespace declarations (xmlns*). When this
+ * feature is enabled, the list of attributes contains the namespace
+ * declarations also.
+ */
+ static const ACEXML_Char namespace_prefixes_feature_[];
/* @} */
@@ -472,6 +492,8 @@ private:
// Feature flags &
int simple_parsing_;
+ int namespaces_;
+ int namespace_prefixes_;
};