From 4fb5872bd233c924cadbf3a4011dcd622765e047 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Fri, 20 Apr 2012 11:03:18 +0400 Subject: [PATCH] msxml3: 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 eb6689981f0..a5b7a32b86a 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; - locator->nb_attributes = nb_namespaces+nb_attributes; + /* skip namespace definitions */ + if ((locator->saxreader->features & NamespacePrefixes) == 0) + nb_namespaces = 0; + + 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; indexnamespaceUri; - 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; indexclsid) { 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 };