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

context Property

Gets the node (subtree) that is applied to the selection.

[Script]

Script Syntax

var objXMLDOMNode = objXMLDOMSelection.context;
objXMLDOMSelection.context = objXMLDOMNode;

Example

The following script example shows what is contained in the context of a selection after a query is executed. It also shows that the selection is reset when this property is changed.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var selection;
xmlDoc.loadXML("<Customer>Microsoft</Customer>");
xmlDoc.setProperty("SelectionLanguage", "XPath");
selection = xmlDoc.selectNodes("//Customer");
alert(selection.context.xml);

The selection.context.xml contains "<Customer>Microsoft</Customer>", selection.length = 1.

xmlDoc.loadXML("<new>none</new>");
alert(selection.context.xml);

The selection.context.xml contains "<new>none</new>", selection.length = 0.

[Visual Basic]

Visual Basic Syntax

Set objXMLDOMNode = objXMLDOMSelection.context
objXMLDOMSelection.context = objXMLDOMNode

Example

The following Microsoft® Visual Basic® example shows what is contained in the context of a selection after a query is executed. It also shows that the selected set is reset when this property is changed.

Dim xmlDoc As New Msxml2.DOMDocument40
Dim selection As Msxml2.IXMLDOMSelection

xmlDoc.loadXML ("<Customer>Microsoft</Customer>")
xmlDoc.setProperty "SelectionLanguage", "XPath"
Set selection = xmlDoc.selectNodes("//Customer")
MsgBox selection.context.xml

The selection.context.xml contains "<Customer>Microsoft</Customer>", selection.length = 1.

xmlDoc.loadXML ("<new>none</new>")
MsgBox selection.context.xml

The selection.context.xml contains "<new>none</new>", selection.length = 0.

[C/C++]

C/C++ Syntax

HRESULT get_context(IXMLDOMNode ** ppNode);
HRESULT putref_context(IXMLDOMNode * pNode);

Parameters

ppNode [out, retval]
The subtree to apply the pattern to.
pNode [in]
The subtree to apply the pattern to.

C/C++ Return Values

S_OK
The value returned if the method is successful.
S_FALSE (for get_context only)
The value returned if the context is invalid.
E_INVALIDARG (for get_context only)
The value returned if the input argument is Null.
E_FAIL (for putref_context only)
The value returned if a node with a different threading model is provided.

Example

The following C/C++ example shows what is contained in the context property after selectNodes is executed.

#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 DOMSelectionContextDemo()
{
   BOOL bResult = FALSE;
   short sResult = FALSE;
   IXMLDOMSelection *pIXMLDOMSelection=NULL;
   IXMLDOMNode *pIXMLDOMNode=NULL;
   IXMLDOMDocument2 *pIXMLDOMDocument2=NULL;
   HRESULT hr;
   BSTR bstrValue;

   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\\samplexml.xml")), &sResult);
            if(SUCCEEDED(hr) && (sResult==VARIANT_TRUE))
            {
               hr=pIXMLDOMDocument2->selectNodes( 
               _T("*/BOOK[TITLE='Cosmos']"),
               (IXMLDOMNodeList**)&pIXMLDOMSelection);
               if(SUCCEEDED(hr))
               {
                  if(SUCCEEDED(hr) && pIXMLDOMSelection)
                  {
                     hr=pIXMLDOMSelection->get_context(&pIXMLDOMNode);
                     if(SUCCEEDED(hr) && pIXMLDOMNode)
                     {
                        hr=pIXMLDOMNode->get_xml(&bstrValue);
                        if(SUCCEEDED(hr))
                           ::MessageBox(NULL, bstrValue, _T("Current 
                              Selection Context"), MB_OK);
                        bResult=TRUE;
                        RELEASE(pIXMLDOMNode);
                     }
                     RELEASE(pIXMLDOMSelection);
                  }
               }
            }
         }
         RELEASE(pIXMLDOMDocument2);
      }
   }
   catch(...)
   {
      CHECK_AND_RELEASE(pIXMLDOMNode);
      CHECK_AND_RELEASE(pIXMLDOMSelection);
      CHECK_AND_RELEASE(pIXMLDOMDocument2);
      DisplayErrorToUser();
   }
   return bResult;
}

Data File: d:\\inetpub\\wwwroot\\samplexml.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>
</COLLECTION>

Output (in a message box)

<?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>
</COLLECTION>

Remarks

Because the selectNodes method can be called on any node type, context can also be assigned any node type. A node from a document different from the one that originally created IXMLDOMSelection can also be specified as long as it has the same threading model. Calling context also resets the state of the node list so that nextNode starts over.

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

Applies to: IXMLDOMSelection


Download de SDK