Newbie has trouble parsing with msxml 4.0 on xp pro

M

malhenry

I am using MSXML 4.0 on WinXP Pro.

I am having two problems.
1. How can I extract the value (of a SINGLE node) such that I do NOT
get the values of all child nodes concatenated together (e.g. all
children of the incident node)?
2. How can I successfully navigate the document? The problem is that
when there are multiple nodes with the same name, I always get the
first instance, not the instance that I want.

Here is an (short) xml file:
<?xml version="1.0" encoding="ISO-8859-1" ?>
- <Traffic>
<date>06-01-25</date>
<time>14:23:24</time>
<city>TO</city>
<sector />
- <incident>
<active>0</active>
<route>403</route>
<direction>WB</direction>
<location>at</location>
<route>6 South</route>
<incident>Collision</incident>
<lane>Right lane</lane>
</incident>
<city>TO</city>
<sector />
- <incident>
<active>1</active>
<route>409</route>
<direction>WB</direction>
<location>at</location>
<route>427</route>
<incident>Car guardrail</incident>
<lane />
</Traffic>


Here are some code snippets:
This method always goes to the first city node:
bool APCCheckXML::procNodeCity(MSXML::IXMLDOMDocument *m_pDoc1,
MSXML::IXMLDOMNode* pCityNode, const char *pCity,
int iCity)
{

HRESULT hr = S_OK; // HRESULT from MSXML calls
BSTR bstrItemText;

BSTR bstrNodeName = ::SysAllocString( L"//city" );
m_pDoc1->selectSingleNode(bstrNodeName, &pCityNode);
hr = pCityNode->get_text(&bstrItemText);
if (hr == S_OK)
{
if(bstrItemText)
{
TRACE(TEXT("city =%S\n"), bstrItemText);

// Convert the BSTR (nodeName) into an ANSI string in order to make
comparison

USES_CONVERSION; // When using an ATL string conversion macro, specify
the USES_CONVERSION
// macro at the beginning of your function in order to avoid
compiler errors

pCity = OLE2CT( bstrItemText );

::SysFreeString(bstrItemText);
bstrItemText = NULL;
pCityNode->Release();
pCityNode = NULL;
}
}

return hr == S_OK ? true : false;
}

The next method prints all child node values of the OUTER incident node

(i.e. incident =0 403 WB at 6 South Collision Right lane) instead of
just the value of the inner incident value (Collision).
bool APCCheckXML::procNodeIncident(MSXML::IXMLDOMDocument *m_pDoc1,
MSXML::IXMLDOMNode* pIncidentNode, const char *pIncident)
{

HRESULT hr = S_OK; // HRESULT from MSXML calls
BSTR bstrItemText;

BSTR bstrNodeName = ::SysAllocString( L"//incident" );
m_pDoc1->selectSingleNode(bstrNodeName, &pIncidentNode);
hr = pIncidentNode->get_text(&bstrItemText);
if (hr == S_OK)
{
if(bstrItemText)
{
TRACE(TEXT("incident =%S\n"), bstrItemText);

// Convert the BSTR (nodeName) into an ANSI string in order to make
comparison

USES_CONVERSION; // When using an ATL string conversion macro, specify
the USES_CONVERSION
// macro at the beginning of your function in order to avoid
compiler errors

pIncident = OLE2CT( bstrItemText );

::SysFreeString(bstrItemText);
bstrItemText = NULL;
pIncidentNode->Release();
pIncidentNode = NULL;
}
}

return hr == S_OK ? true : false;
}
Thanks!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Memory leaking 6

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top