Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Newbie has trouble parsing with msxml 4.0 on xp pro

Reply
Thread Tools

Newbie has trouble parsing with msxml 4.0 on xp pro

 
 
malhenry@hotmail.com
Guest
Posts: n/a
 
      04-27-2006
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:rocNodeCity(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:rocNodeIncident(MSXML::IXMLDOMDocume nt *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!!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie has trouble setting up redmine Jar Sconce Ruby 1 05-11-2009 12:30 PM
msxml scripts and xstlArgumentList entension objects. Can I combinethem? steve_h ASP .Net 3 11-05-2003 06:38 PM
Re: MVP? Index error on nested element using System.xml but NOT using msxml??? William F. Robertson, Jr. ASP .Net 1 06-25-2003 08:08 PM
What parses the xml/xsl transform in asp.net? System.xml NOT msxml? KathyB ASP .Net 0 06-25-2003 05:03 PM



Advertisments