nedcomp hosting homepage

Producten en diensten
Dedicated servers
Datacenter informatie
Partners, resellers
Helpdesk informatie
Technische docs, tools
Support homepage
ASP componenten
Praktische ASP, ASP.NET
Visual route server
Whois (domein gegevens)
Software documentatie
Whitepapers
Zoeken
Nedcomp / algemeen

Zoeken
 

Copyright © Nedcomp Hosting
Telefoon nr :   +31 184 670111
Fax nummer :   +31 184 631384
E-mailadres :   info@nedcomp.nl
 

Microsoft XML Core Services (MSXML) 4.0 - DOM Reference

IXMLDOMSelection

Represents the list of nodes that match a given XML Path Language (XPath) or XSL Patterns expression.

[Script]

Example

In the following Microsoft® JScript® example, you can simply call the IXMLDOMSelection methods on the object returned from selectNodes.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.setProperty("SelectionLanguage", "XPath");
var selection = xmlDoc.selectNodes("//book");
var expr = selection.expr; //This returns "//book"
alert(expr);
[Visual Basic]

Example

In the following Microsoft Visual Basic® example, the selectNodes method returns IXMLDOMNodeList, so you have to cast the result of selectNodes into an IXMLDOMSelection.

Dim xmlDoc As New Msxml2.DOMDocument
Dim Selection As IXMLDOMSelection
Dim sExpr As String
xmlDoc.async = False
xmlDoc.setProperty "SelectionLanguage", "XPath"
xmlDoc.Load ("books.xml")
Set Selection = xmlDoc.selectNodes("//book")
expr = Selection.expr       ' This returns "//book"
MsgBox (expr)
[C/C++]

Example

In the following C/C++ example, IXMLDOMSelection inherits the threading model of the document that created it.

#import "msxml4.dll"
using namespace MSXML2;

#define CHECK_AND_RELEASE(pInterface)  \
if(pInterface) \
   {\
pInterface->Release();\
pInterface = NULL;\
   }\

#define RELEASE(pInterface)  \
   {\
pInterface->Release();\
pInterface = NULL;\
   }\

BOOL DOMSelectionDemo()
{
   BOOL bResult = FALSE;
   short sResult = FALSE;
   IXMLDOMSelection *pIXMLDOMSelection=NULL;
   IXMLDOMNodeList *pIXMLDOMNodeList=NULL;
   IXMLDOMNode *pIXMLDOMNode=NULL;
   IXMLDOMDocument2 *pIXMLDOMDocument2=NULL;
   BSTR bstrValue;
   HRESULT hr;

   try
   {
      hr=CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_SERVER,
               IID_IXMLDOMDocument2, (LPVOID*)(&pIXMLDOMDocument2));
      SUCCEEDED(hr) ? 0 : throw hr;

      if(pIXMLDOMDocument2)
      {
         hr=pIXMLDOMDocument2->put_async(VARIANT_FALSE);
         if(SUCCEEDED(hr))
         {
            hr=pIXMLDOMDocument2->load(_variant_t( 
      _T("d:\\inetpub\\wwwroot\\samplexmldtd.xml")), &sResult);
            if(SUCCEEDED(hr) && (sResult==VARIANT_TRUE))
            {
               hr=pIXMLDOMDocument2->selectNodes( 
               _T("*/BOOK[TITLE='Cosmos']"), &pIXMLDOMNodeList);
               if(SUCCEEDED(hr))
               {
                  hr=pIXMLDOMNodeList->QueryInterface(IID_IXMLDOMSelection
                     ,(void**)&pIXMLDOMSelection );
                  if(SUCCEEDED(hr) && pIXMLDOMSelection)
                  {
                     LONG uLength;

                     bResult=TRUE;
                     hr=pIXMLDOMSelection->get_length(&uLength);
                     if(SUCCEEDED(hr))
                     {
                        for(int iIndex=0; iIndex < uLength; iIndex++)
                        {
                           // remove all the nodes from the list-display 
                           // them as they are removed.
                           hr=pIXMLDOMSelection->removeNext(
                              &pIXMLDOMNode);
                           if(SUCCEEDED(hr) && pIXMLDOMNode)
                           {   
                              hr=pIXMLDOMNode->get_text(&bstrValue);
                              if(SUCCEEDED(hr))
                                 ::MessageBox(NULL, bstrValue, _T("Node
                                  Text"), MB_OK);
                              RELEASE(pIXMLDOMNode);
                           }
                        }
                     }
                     RELEASE(pIXMLDOMSelection);
                  }
                  RELEASE(pIXMLDOMNodeList);
               }
            }
         }
         RELEASE(pIXMLDOMDocument2);
      }
   }
   catch(...)
   {
      CHECK_AND_RELEASE(pIXMLDOMNode);
      CHECK_AND_RELEASE(pIXMLDOMDocument2);
      CHECK_AND_RELEASE(pIXMLDOMNodeList);
      CHECK_AND_RELEASE(pIXMLDOMSelection);
      DisplayErrorToUser();
   }
   return bResult;
}

d:\\inetpub\\wwwroot\\samplexmldtd.xml

<?xml version='1.0'?>
<COLLECTION xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <DATE dt:dt="datetime">1998-10-13T15:56:00</DATE>
  <BOOK>
    <TITLE>Cosmos</TITLE>
    <AUTHOR>Carl Sagan</AUTHOR>
    <PUBLISHER>Ballantine Books</PUBLISHER>
 </BOOK>
 <BOOK>
    <TITLE>Catwings</TITLE>
    <AUTHOR>Ursula K. Le Guin</AUTHOR>
    <PUBLISHER>Scholastic</PUBLISHER>
 </BOOK>
 <BOOK>
    <TITLE>Home Town</TITLE>
    <AUTHOR>Tracy Kidder</AUTHOR>
    <PUBLISHER>Random House</PUBLISHER>
 </BOOK>
</COLLECTION>

Output (in a message box)

Cosmos Carl Sagan Ballantine Books

Remarks

IXMLDOMSelection is created through the selectNodes method on IXMLDOMDocument2. IXMLDOMSelection is an extension of the World Wide Web Consortium (W3C) DOM.

Requirements

Implementation: msxml4.dll, msxml2.lib

[C/C++]

Header and IDL files: msxml2.h, msxml2.idl

Version-Dependent ProgID: Msxml2.DOMDocument.4.0, Msxml2.FreeThreadedDOMDocument.4.0

Version-Dependent CLSID: 88d969c0-f192-11d4-a65f-0040963251e5

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

IXMLDOMSelection Members


Download de SDK