[xml] SelectSingleNode



I am working on a project to port a Win32 application that uses MSXML to a POSIX environment with LIBXML2. The good news is that this project includes an abstraction layer on top of the MSXML implementation, the bad news is that the Win32 impl makes heavy use of the MSXML “SelectSingleNode” API (which basically just takes an XPath query and returns a pointer to the first node that matches).

 

Easy enough to implement using LIBXML2, except the app layer expects to obtain the namespace mappings necessary to evaluate the XPath entirely from within the document. In Win32, it’s a matter of requesting the namespaces declared in the document in the form of an schema collection object:

 

CComPtr<IXMLDOMSchemaCollection> pReadOnlyCollection;

VERIFY(SUCCEEDED(m_pIDocument->get_namespaces(&pReadOnlyCollection)));

// walk through the collection, extract the URI from each member, build namespace declaration strings like "xmlns:%s='%s'")

// register the mapping with the space-separated list of namespace declaration attributes created above

HRESULT hr = m_pIDocument->setProperty (bstr_t (L"SelectionNamespaces"), variant_t (strSelectionNamespaces));

 

I looked through the LIBXML2 doc and didn’t find anything quite equivalent. Is there a simple way to retrieve each namespace declared in a given instance document without having to resort to a element-by-element search?

 

Thanks,

- Paul C.

 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]