用VARIANT类型变量得到属性后,它的vt老是BSTR,如果有一个节点为:
<height num="1000"></height>
请问我应该怎样才能得到整数1000而不是字符串的"1000"?

解决方案 »

  1.   

    get string "1000", then use atoi(...)
      

  2.   

    msXML的解释:
    nodeValue Property  [C/C++]
    Contains the text associated with the node.[Script] 
    Script Syntax
    objValue = oXMLDOMNode.nodeValue;
    objXMLDOMNode.nodeValue = objValue;
    Example
    The following script example creates an IXMLDOMNode object and tests if it is a comment node. If it is, it displays its value.var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
    var currNode;
    xmlDoc.async = false;
    xmlDoc.async = false;
    xmlDoc.loadXML("<root><!-- Hello --></root>");
    if (xmlDoc.parseError.errorCode <> 0) {
       var myErr = xmlDoc.parseError;
       alert("You have error " + myErr.reason);
    } else {
       currNode = xmlDoc.documentElement.childNodes.item(0);
       if (currNode.nodeTypeString == "comment") {
          alert(currNode.nodeValue);
       }
    }
    [Visual Basic] 
    Visual Basic Syntax
    objValue = oXMLDOMNode.nodeValue
    objXMLDOMNode.nodeValue = objValue
    Example
    The following Microsoft&#174; Visual Basic&#174; example creates an IXMLDOMNode object and tests if it is a comment node. If it is, it displays its value.Dim xmlDoc As New Msxml2.DOMDocument40
    Dim currNode As IXMLDOMNode
    xmlDoc.async = False
    xmlDoc.Load ("books.xml")
    If (xmlDoc.parseError.errorCode <> 0) Then
       Dim myErr
       Set myErr = xmlDoc.parseError
       MsgBox("You have error " & myErr.reason)
    Else
       Set currNode = xmlDoc.documentElement.childNodes.Item(0)
       If currNode.nodeTypeString = "comment" Then
          MsgBox currNode.nodeValue
       End If
    End If
    [C/C++] 
    C/C++ Syntax
    HRESULT get_nodeValue(
        VARIANT *value);
    HRESULT put_nodeValue(
        VARIANT value);
    Parameters
    value [out, retval][in] 
    Node value; depends on the nodeType property. 
    C/C++ Return Values
    S_OK 
    Value returned if successful. 
    S_FALSE (for get_nodeValue only) 
    Value when returning Null. 
    E_INVALIDARG (for get_nodeValue only) 
    Value returned if the value parameter is Null. 
    E_FAIL (for get_nodeValue only) 
    Value returned if an error occurs. 
    Res
    Variant. The property is read/write.This value depends on the value of the nodeType property.
    NODE_ATTRIBUTE Contains a string representing the value of the attribute. For attributes with subnodes, this is the concatenated text of all subnodes with entities expanded. Setting this value deletes all children of the node and replaces them with a single text node containing the value written. 我的代码
    hr = pAttribute->get_nodeValue(&var);
    if (FAILED(hr))
    {
    goto clean;
    }
    ZeroMemory(psTemp, MAX_PATH);
    wcstombs(psTemp, var.bstrVal, wcslen(var.bstrVal));
    if (wcscmp(bstr, L"HotKeyModifiers") == 0)
    {
    qli.m_uiHotkeyModifiers = (UINT)atoi(psTemp);
    }