xmllite: Support reporting of a local name and value for attributes.

This commit is contained in:
Nikolay Sivov 2013-08-19 10:42:38 +04:00 committed by Alexandre Julliard
parent 36d999527b
commit e51ab3c03a
2 changed files with 35 additions and 13 deletions

View File

@ -226,6 +226,7 @@ struct element
{ {
struct list entry; struct list entry;
strval qname; strval qname;
strval localname;
}; };
typedef struct typedef struct
@ -437,7 +438,7 @@ static void reader_dec_depth(xmlreader *reader)
if (reader->depth > 1) reader->depth--; if (reader->depth > 1) reader->depth--;
} }
static HRESULT reader_push_element(xmlreader *reader, strval *qname) static HRESULT reader_push_element(xmlreader *reader, strval *qname, strval *localname)
{ {
struct element *elem; struct element *elem;
HRESULT hr; HRESULT hr;
@ -451,6 +452,14 @@ static HRESULT reader_push_element(xmlreader *reader, strval *qname)
return hr; return hr;
} }
hr = reader_strvaldup(reader, localname, &elem->localname);
if (FAILED(hr))
{
reader_free_strvalued(reader, &elem->qname);
reader_free(reader, elem);
return hr;
}
if (!list_empty(&reader->elements)) if (!list_empty(&reader->elements))
{ {
hr = reader_inc_depth(reader); hr = reader_inc_depth(reader);
@ -473,6 +482,7 @@ static void reader_pop_element(xmlreader *reader)
{ {
list_remove(&elem->entry); list_remove(&elem->entry);
reader_free_strvalued(reader, &elem->qname); reader_free_strvalued(reader, &elem->qname);
reader_free_strvalued(reader, &elem->localname);
reader_free(reader, elem); reader_free(reader, elem);
reader_dec_depth(reader); reader_dec_depth(reader);
} }
@ -1524,8 +1534,7 @@ static HRESULT reader_parse_sys_literal(xmlreader *reader, strval *literal)
} }
if (*cur == quote) reader_skipn(reader, 1); if (*cur == quote) reader_skipn(reader, 1);
literal->str = start; reader_init_strvalue(start, cur-start, literal);
literal->len = cur-start;
TRACE("%s\n", debugstr_wn(start, cur-start)); TRACE("%s\n", debugstr_wn(start, cur-start));
return S_OK; return S_OK;
} }
@ -1872,7 +1881,7 @@ static HRESULT reader_parse_stag(xmlreader *reader, strval *prefix, strval *loca
{ {
/* skip '>' */ /* skip '>' */
reader_skipn(reader, 1); reader_skipn(reader, 1);
return reader_push_element(reader, qname); return reader_push_element(reader, qname, local);
} }
hr = reader_parse_attribute(reader); hr = reader_parse_attribute(reader);
@ -2413,6 +2422,9 @@ static HRESULT WINAPI xmlreader_MoveToFirstAttribute(IXmlReader* iface)
if (!This->attr_count) return S_FALSE; if (!This->attr_count) return S_FALSE;
This->attr = LIST_ENTRY(list_head(&This->attrs), struct attribute, entry); This->attr = LIST_ENTRY(list_head(&This->attrs), struct attribute, entry);
reader_set_strvalue(This, StringValue_LocalName, &This->attr->localname);
reader_set_strvalue(This, StringValue_Value, &This->attr->value);
return S_OK; return S_OK;
} }
@ -2430,7 +2442,11 @@ static HRESULT WINAPI xmlreader_MoveToNextAttribute(IXmlReader* iface)
next = list_next(&This->attrs, &This->attr->entry); next = list_next(&This->attrs, &This->attr->entry);
if (next) if (next)
{
This->attr = LIST_ENTRY(next, struct attribute, entry); This->attr = LIST_ENTRY(next, struct attribute, entry);
reader_set_strvalue(This, StringValue_LocalName, &This->attr->localname);
reader_set_strvalue(This, StringValue_Value, &This->attr->value);
}
return next ? S_OK : S_FALSE; return next ? S_OK : S_FALSE;
} }
@ -2446,11 +2462,21 @@ static HRESULT WINAPI xmlreader_MoveToAttributeByName(IXmlReader* iface,
static HRESULT WINAPI xmlreader_MoveToElement(IXmlReader* iface) static HRESULT WINAPI xmlreader_MoveToElement(IXmlReader* iface)
{ {
xmlreader *This = impl_from_IXmlReader(iface); xmlreader *This = impl_from_IXmlReader(iface);
struct element *elem;
TRACE("(%p)\n", This); TRACE("(%p)\n", This);
if (!This->attr_count) return S_FALSE; if (!This->attr_count) return S_FALSE;
This->attr = NULL; This->attr = NULL;
/* FIXME: support other node types with 'attributes' like DTD */
elem = LIST_ENTRY(list_head(&This->elements), struct element, entry);
if (elem)
{
reader_set_strvalue(This, StringValue_QualifiedName, &elem->qname);
reader_set_strvalue(This, StringValue_LocalName, &elem->localname);
}
return S_OK; return S_OK;
} }

View File

@ -1048,18 +1048,16 @@ static void test_read_dtd(void)
str = NULL; str = NULL;
hr = IXmlReader_GetLocalName(reader, &str, &len); hr = IXmlReader_GetLocalName(reader, &str, &len);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
todo_wine {
ok(len == lstrlenW(sysW), "got %u\n", len); ok(len == lstrlenW(sysW), "got %u\n", len);
ok(!lstrcmpW(str, sysW), "got %s\n", wine_dbgstr_w(str)); ok(!lstrcmpW(str, sysW), "got %s\n", wine_dbgstr_w(str));
}
len = 0; len = 0;
str = NULL; str = NULL;
hr = IXmlReader_GetValue(reader, &str, &len); hr = IXmlReader_GetValue(reader, &str, &len);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
todo_wine {
ok(len == lstrlenW(sysvalW), "got %u\n", len); ok(len == lstrlenW(sysvalW), "got %u\n", len);
ok(!lstrcmpW(str, sysvalW), "got %s\n", wine_dbgstr_w(str)); ok(!lstrcmpW(str, sysvalW), "got %s\n", wine_dbgstr_w(str));
}
hr = IXmlReader_MoveToElement(reader); hr = IXmlReader_MoveToElement(reader);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
@ -1067,9 +1065,10 @@ todo_wine {
str = NULL; str = NULL;
hr = IXmlReader_GetLocalName(reader, &str, &len); hr = IXmlReader_GetLocalName(reader, &str, &len);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
todo_wine {
ok(len == lstrlenW(dtdnameW), "got %u\n", len); ok(len == lstrlenW(dtdnameW), "got %u\n", len);
ok(!lstrcmpW(str, dtdnameW), "got %s\n", wine_dbgstr_w(str)); ok(!lstrcmpW(str, dtdnameW), "got %s\n", wine_dbgstr_w(str));
}
len = 0; len = 0;
str = NULL; str = NULL;
hr = IXmlReader_GetQualifiedName(reader, &str, &len); hr = IXmlReader_GetQualifiedName(reader, &str, &len);
@ -1617,12 +1616,11 @@ static void test_read_attribute(void)
str = NULL; str = NULL;
hr = IXmlReader_GetLocalName(reader, &str, &len); hr = IXmlReader_GetLocalName(reader, &str, &len);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
todo_wine {
ok(len == strlen(test->name), "got %u\n", len); ok(len == strlen(test->name), "got %u\n", len);
str_exp = a2w(test->name); str_exp = a2w(test->name);
ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str)); ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
free_str(str_exp); free_str(str_exp);
}
len = 1; len = 1;
str = NULL; str = NULL;
hr = IXmlReader_GetQualifiedName(reader, &str, &len); hr = IXmlReader_GetQualifiedName(reader, &str, &len);
@ -1638,13 +1636,11 @@ static void test_read_attribute(void)
str = NULL; str = NULL;
hr = IXmlReader_GetValue(reader, &str, &len); hr = IXmlReader_GetValue(reader, &str, &len);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
todo_wine {
ok(len == strlen(test->value), "got %u\n", len); ok(len == strlen(test->value), "got %u\n", len);
str_exp = a2w(test->value); str_exp = a2w(test->value);
ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str)); ok(!lstrcmpW(str, str_exp), "got %s\n", wine_dbgstr_w(str));
free_str(str_exp); free_str(str_exp);
} }
}
IStream_Release(stream); IStream_Release(stream);
test++; test++;