msxml3: Support 'namespace-prefixes' feature
Nikolay Sivov
nsivov at codeweavers.com
Fri Apr 20 02:13:38 CDT 2012
Support 'namespace-prefixes' feature
-------------- next part --------------
>From 6579a590bd9ec8833c934d020c5b184da0e9efa8 Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov at codeweavers.com>
Date: Fri, 20 Apr 2012 11:03:18 +0400
Subject: [PATCH 1/2] Support 'namespace-prefixes' feature
---
dlls/msxml3/saxreader.c | 43 ++++++++++++---------
dlls/msxml3/tests/saxreader.c | 83 ++++++++++++++++++++++++++++++++++++++--
2 files changed, 102 insertions(+), 24 deletions(-)
diff --git a/dlls/msxml3/saxreader.c b/dlls/msxml3/saxreader.c
index eb66899..a5b7a32 100644
--- a/dlls/msxml3/saxreader.c
+++ b/dlls/msxml3/saxreader.c
@@ -1160,9 +1160,13 @@ static HRESULT SAXAttributes_populate(saxlocator *locator,
static const WCHAR xmlnsW[] = { 'x','m','l','n','s',0 };
struct _attributes *attrs;
- int index;
+ int i;
+
+ /* skip namespace definitions */
+ if ((locator->saxreader->features & NamespacePrefixes) == 0)
+ nb_namespaces = 0;
- locator->nb_attributes = nb_namespaces+nb_attributes;
+ locator->nb_attributes = nb_namespaces + nb_attributes;
if(locator->nb_attributes > locator->attributesSize)
{
attrs = heap_realloc(locator->attributes, sizeof(struct _attributes)*locator->nb_attributes*2);
@@ -1178,31 +1182,31 @@ static HRESULT SAXAttributes_populate(saxlocator *locator,
attrs = locator->attributes;
}
- for(index=0; index<nb_namespaces; index++)
+ for (i = 0; i < nb_namespaces; i++)
{
- attrs[nb_attributes+index].szLocalname = SysAllocStringLen(NULL, 0);
- attrs[nb_attributes+index].szURI = locator->namespaceUri;
- attrs[nb_attributes+index].szValue = bstr_from_xmlChar(xmlNamespaces[2*index+1]);
- if(!xmlNamespaces[2*index])
- attrs[nb_attributes+index].szQName = SysAllocString(xmlnsW);
+ attrs[nb_attributes+i].szLocalname = SysAllocStringLen(NULL, 0);
+ attrs[nb_attributes+i].szURI = locator->namespaceUri;
+ attrs[nb_attributes+i].szValue = bstr_from_xmlChar(xmlNamespaces[2*i+1]);
+ if(!xmlNamespaces[2*i])
+ attrs[nb_attributes+i].szQName = SysAllocString(xmlnsW);
else
- attrs[nb_attributes+index].szQName = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]);
+ attrs[nb_attributes+i].szQName = QName_from_xmlChar(xmlns, xmlNamespaces[2*i]);
}
- for(index=0; index<nb_attributes; index++)
+ for (i = 0; i < nb_attributes; i++)
{
static const xmlChar xmlA[] = "xml";
- if (xmlStrEqual(xmlAttributes[index*5+1], xmlA))
- attrs[index].szURI = bstr_from_xmlChar(xmlAttributes[index*5+2]);
+ if (xmlStrEqual(xmlAttributes[i*5+1], xmlA))
+ attrs[i].szURI = bstr_from_xmlChar(xmlAttributes[i*5+2]);
else
- attrs[index].szURI = find_element_uri(locator, xmlAttributes[index*5+2]);
+ attrs[i].szURI = find_element_uri(locator, xmlAttributes[i*5+2]);
- attrs[index].szLocalname = bstr_from_xmlChar(xmlAttributes[index*5]);
- attrs[index].szValue = bstr_from_xmlCharN(xmlAttributes[index*5+3],
- xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
- attrs[index].szQName = QName_from_xmlChar(xmlAttributes[index*5+1],
- xmlAttributes[index*5]);
+ attrs[i].szLocalname = bstr_from_xmlChar(xmlAttributes[i*5]);
+ attrs[i].szValue = bstr_from_xmlCharN(xmlAttributes[i*5+3],
+ xmlAttributes[i*5+4]-xmlAttributes[i*5+3]);
+ attrs[i].szQName = QName_from_xmlChar(xmlAttributes[i*5+1],
+ xmlAttributes[i*5]);
}
return S_OK;
@@ -2849,7 +2853,8 @@ static HRESULT WINAPI saxxmlreader_putFeature(
/* accepted cases */
if ((feature == ExternalGeneralEntities && value == VARIANT_FALSE) ||
(feature == ExternalParameterEntities && value == VARIANT_FALSE) ||
- feature == Namespaces)
+ feature == Namespaces ||
+ feature == NamespacePrefixes)
{
return set_feature_value(This, feature, value);
}
diff --git a/dlls/msxml3/tests/saxreader.c b/dlls/msxml3/tests/saxreader.c
index 5c768f4..00a3553 100644
--- a/dlls/msxml3/tests/saxreader.c
+++ b/dlls/msxml3/tests/saxreader.c
@@ -787,6 +787,50 @@ static struct call_entry content_handler_test_attributes_alternate_6[] = {
{ CH_ENDTEST }
};
+/* 'namespaces' is on, 'namespace-prefixes' if off */
+static struct attribute_entry ch_attributes_no_prefix[] = {
+ { "prefix_test", "arg1", "test:arg1", "arg1" },
+ { "", "arg2", "arg2", "arg2" },
+ { "prefix_test", "ar3", "test:ar3", "arg3" },
+ { NULL }
+};
+
+static struct call_entry content_handler_test_attributes_alt_no_prefix[] = {
+ { CH_PUTDOCUMENTLOCATOR, 1, 0, S_OK },
+ { CH_STARTDOCUMENT, 1, 22, S_OK },
+ { CH_STARTPREFIXMAPPING, 2, 95, S_OK, "test", "prefix_test" },
+ { CH_STARTPREFIXMAPPING, 2, 95, S_OK, "", "prefix" },
+ { CH_STARTELEMENT, 2, 95, S_OK, "prefix", "document", "document", ch_attributes_no_prefix },
+ { CH_CHARACTERS, 3, 1, S_OK, "\n" },
+ { CH_STARTPREFIXMAPPING, 3, 24, S_OK, "p", "test" },
+ { CH_STARTELEMENT, 3, 24, S_OK, "prefix", "node1", "node1", NULL },
+ { CH_ENDELEMENT, 3, 24, S_OK, "prefix", "node1", "node1" },
+ { CH_ENDPREFIXMAPPING, 3, 24, S_OK, "p" },
+ { CH_ENDELEMENT, 3, 35, S_OK, "prefix", "document", "document" },
+ { CH_ENDPREFIXMAPPING, 3, 35, S_OK, "test" },
+ { CH_ENDPREFIXMAPPING, 3, 35, S_OK, "" },
+ { CH_ENDDOCUMENT, 4, 0, S_OK },
+ { CH_ENDTEST }
+};
+
+static struct call_entry content_handler_test_attributes_no_prefix[] = {
+ { CH_PUTDOCUMENTLOCATOR, 0, 0, S_OK },
+ { CH_STARTDOCUMENT, 0, 0, S_OK },
+ { CH_STARTPREFIXMAPPING, 2, 96, S_OK, "test", "prefix_test" },
+ { CH_STARTPREFIXMAPPING, 2, 96, S_OK, "", "prefix" },
+ { CH_STARTELEMENT, 2, 96, S_OK, "prefix", "document", "document", ch_attributes_no_prefix },
+ { CH_CHARACTERS, 2, 96, S_OK, "\n" },
+ { CH_STARTPREFIXMAPPING, 3, 25, S_OK, "p", "test" },
+ { CH_STARTELEMENT, 3, 25, S_OK, "prefix", "node1", "node1", NULL },
+ { CH_ENDELEMENT, 3, 25, S_OK, "prefix", "node1", "node1" },
+ { CH_ENDPREFIXMAPPING, 3, 25, S_OK, "p" },
+ { CH_ENDELEMENT, 3, 27, S_OK, "prefix", "document", "document" },
+ { CH_ENDPREFIXMAPPING, 3, 27, S_OK, "" },
+ { CH_ENDPREFIXMAPPING, 3, 27, S_OK, "test" },
+ { CH_ENDDOCUMENT, 0, 0 },
+ { CH_ENDTEST }
+};
+
static struct attribute_entry xmlspace_attrs[] = {
{ "http://www.w3.org/XML/1998/namespace", "space", "xml:space", "preserve" },
{ NULL }
@@ -1765,12 +1809,12 @@ static void test_saxreader(void)
static const CHAR testXmlA[] = "test.xml";
static const WCHAR testXmlW[] = {'t','e','s','t','.','x','m','l',0};
IXMLDOMDocument *doc;
- BSTR str;
VARIANT_BOOL v;
while (table->clsid)
{
struct call_entry *test_seq;
+ BSTR str;
if (!is_clsid_supported(table->clsid, reader_support_data))
{
@@ -1967,6 +2011,7 @@ static void test_saxreader(void)
str = SysAllocString(szSimpleXML);
hr = IXMLDOMDocument_loadXML(doc, str, &v);
EXPECT_HR(hr, S_OK);
+ SysFreeString(str);
V_VT(&var) = VT_UNKNOWN;
V_UNKNOWN(&var) = (IUnknown*)doc;
@@ -2031,15 +2076,42 @@ static void test_saxreader(void)
hr = ISAXXMLReader_parse(reader, var);
EXPECT_HR(hr, S_OK);
ok_sequence(sequences, CONTENT_HANDLER_INDEX, test_seq, "content test attributes", TRUE);
+ hr = ISAXXMLReader_putFeature(reader, _bstr_("http://xml.org/sax/features/namespaces"), VARIANT_TRUE);
+ EXPECT_HR(hr, S_OK);
+
+ /* switch off 'namespace-prefixes' feature */
+ hr = ISAXXMLReader_putFeature(reader, _bstr_("http://xml.org/sax/features/namespace-prefixes"), VARIANT_FALSE);
+ EXPECT_HR(hr, S_OK);
+
+ CreateStreamOnHGlobal(NULL, TRUE, &stream);
+ size.QuadPart = strlen(test_attributes);
+ IStream_SetSize(stream, size);
+ IStream_Write(stream, test_attributes, strlen(test_attributes), &written);
+ pos.QuadPart = 0;
+ IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
+ V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
+ V_UNKNOWN(&var) = (IUnknown*)stream;
+
+ if (IsEqualGUID(table->clsid, &CLSID_SAXXMLReader40) ||
+ IsEqualGUID(table->clsid, &CLSID_SAXXMLReader60))
+ {
+ test_seq = content_handler_test_attributes_alt_no_prefix;
+ }
+ else
+ test_seq = content_handler_test_attributes_no_prefix;
+
+ set_expected_seq(test_seq);
+ hr = ISAXXMLReader_parse(reader, var);
+ EXPECT_HR(hr, S_OK);
+ ok_sequence(sequences, CONTENT_HANDLER_INDEX, test_seq, "content test attributes", FALSE);
+
+ hr = ISAXXMLReader_putFeature(reader, _bstr_("http://xml.org/sax/features/namespace-prefixes"), VARIANT_TRUE);
+ EXPECT_HR(hr, S_OK);
ISAXXMLReader_Release(reader);
table++;
}
- return;
-
- ISAXXMLReader_Release(reader);
- SysFreeString(str);
free_bstrs();
}
@@ -2161,6 +2233,7 @@ static const struct feature_ns_entry_t feature_ns_entry_data[] = {
static const char *feature_names[] = {
"http://xml.org/sax/features/namespaces",
+ "http://xml.org/sax/features/namespace-prefixes",
0
};
--
1.5.6.5
More information about the wine-patches
mailing list