On 5/27/21 10:56 AM, Dmitry Timoshkov wrote:
Nikolay Sivov <nsivov(a)codeweavers.com> wrote:
On 5/20/21 9:50 AM, Dmitry Timoshkov wrote:
+static char *xmldoc_encoding(IXMLDOMDocument3 *doc) +{ + HRESULT hr; + IXMLDOMNode *node; + char *encoding = NULL; + + hr = IXMLDOMDocument3_get_firstChild(doc, &node); + if (hr == S_OK) + { + DOMNodeType type; + + hr = IXMLDOMNode_get_nodeType(node, &type); + if (hr == S_OK && type == NODE_PROCESSING_INSTRUCTION) + { + IXMLDOMProcessingInstruction *pi; + IXMLDOMNode *item; + IXMLDOMNamedNodeMap *node_map; + + hr = IXMLDOMNode_QueryInterface(node, &IID_IXMLDOMProcessingInstruction, (void **)&pi); + if (hr == S_OK) + { + hr = IXMLDOMNode_get_attributes(node, &node_map); + if (hr == S_OK) + { + static const WCHAR encodingW[] = {'e','n','c','o','d','i','n','g',0}; + BSTR bstr; + + bstr = SysAllocString(encodingW); + hr = IXMLDOMNamedNodeMap_getNamedItem(node_map, bstr, &item); + SysFreeString(bstr); + if (hr == S_OK) + { + VARIANT var; + + hr = IXMLDOMNode_get_nodeValue(item, &var); + if (hr == S_OK) + { + if (V_VT(&var) == VT_BSTR) + encoding = (char *)xmlchar_from_wchar(V_BSTR(&var)); + + VariantClear(&var); + } + } + + IXMLDOMNamedNodeMap_Release(node_map); + } + + IXMLDOMProcessingInstruction_Release(pi); + } + } + + IXMLDOMNode_Release(node); + } + + return encoding; +} Why all this complexity? Isn't it the same as reading current "encoding" value from artificially linked PI node? Do you mean checking the first document child node type for XML_PI_NODE and directly calling xmlGetProp("encoding")? Or something else?
xmlGetProp() won't get you anything for PI node, as I understand. You could read it from content like in parse_xml_decl() from first patch, but only for attribute that matters.