Newbie has trouble parsing with msxml 4.0 on xp pro

Discussion in 'XML' started by malhenry@hotmail.com, Apr 27, 2006.

  1. Guest

    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!!
     
    , Apr 27, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    710
  2. /usr/ceo
    Replies:
    32
    Views:
    1,957
    Mark Space
    Sep 15, 2008
  3. Wayne Erfling
    Replies:
    0
    Views:
    366
    Wayne Erfling
    Nov 18, 2006
  4. Grehom
    Replies:
    2
    Views:
    102
    Grehom
    Jun 9, 2007
  5. Jar Sconce
    Replies:
    1
    Views:
    91
    Mark Thomas
    May 11, 2009
Loading...

Share This Page