Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: help with selectSingleNode

From: v-schang@------.---------.--- (------ -----[----])
To: NULL
Date: 6/3/2004 11:53:00 AM
Hi Developer,

From your description, you are using the MSXML component to parse a XML 
Schema file and is wondering how to select a child node from a give 
IXMLDOMNode using the selectSingleNode method, yes?

I'm not sure what version of MSXML component are you using , I've done a 
simple test via MSXML3, we can still use XPATH from the give node to select 
a certain child node under it. Here is the code of My test app:

===========main cpp file===========================
#include "stdafx.h"
#include <stdio.h>
#import <msxml3.dll>
using namespace MSXML2;



int main(int argc, char* argv[])
{
	IXMLDOMDocumentPtr pXMLDom;
   HRESULT hr;



   CoInitialize(NULL);
	
   hr = pXMLDom.CreateInstance(__uuidof(DOMDocument30));
   if (FAILED(hr)) 
   {
      printf("Failed to instantiate DOMDocument40 class\n");
      return -1;
   }


   
   pXMLDom->async = VARIANT_FALSE;
   if ( pXMLDom->load("schema.xml") != VARIANT_TRUE)
   {
      printf("Failed load xml data from file.\n%s\n",
         (LPCSTR)pXMLDom->parseError->Getreason());
      return -1;
   }

    IXMLDOMNodePtr pNode = 
pXMLDom->selectSingleNode("//xs:schema/xs:element/xs:complexType/xs:choice/x
s:element");
   pXMLDom->selectSingleNode(
   IXMLDOMNodePtr pSubNode = NULL;
   if (pNode == NULL)
   {
      printf("Invalid node fetched.\n%s\n",
         (LPCSTR)pXMLDom->parseError->Getreason());
   }
   else
   {
      printf("Result from selectSingleNode:\nNode, <%s>:\n\t%s\n\n",
         (LPCSTR)pNode->nodeName, (LPCSTR)pNode->xml);
		
	  pSubNode = 
pNode->selectSingleNode("//xs:element/xs:complexType/xs:sequence");
		
	  if (pSubNode == NULL)
	  {
		printf("Invalid node fetched.\n%s\n",
			(LPCSTR)pXMLDom->parseError->Getreason());
	  }
      else
	  {
		printf("Result from selectSingleNode:\nNode, <%s>:\n\t%s\n\n",
			(LPCSTR)pSubNode->nodeName, (LPCSTR)pNode->xml);
		
	  }

   }

   pXMLDom.Release();
   pNode.Release();
   pSubNode.Release();
   CoUninitialize();

   getchar();
   return 0;

}

============test schema file==================
<?xml version="1.0" ?>
<xs:schema id="Dataset1" targetNamespace="http://tempuri.org/Dataset1.xsd" 
xmlns:mstns="http://tempuri.org/Dataset1.xsd" 
xmlns="http://tempuri.org/Dataset1.xsd" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" 
attributeFormDefault="qualified" elementFormDefault="qualified">
  <xs:element name="Dataset1" msdata:IsDataSet="true">
    <xs:complexType>
      <xs:choice maxOccurs="unbounded">
        <xs:element name="venue_seats">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="venue_id" msdata:ReadOnly="true" 
msdata:AutoIncrement="true" type="xs:int" />
              <xs:element name="seat_id" type="xs:int" minOccurs="0" />
              <xs:element name="a" type="xs:string" minOccurs="0" />
              <xs:element name="Table1" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="id" msdata:ReadOnly="true" 
msdata:AutoIncrement="true" type="xs:int" />
                    <xs:element name="a" type="xs:string" minOccurs="0" />
                    <xs:element name="b" type="xs:string" minOccurs="0" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
    <xs:unique name="Dataset1Key2" msdata:PrimaryKey="true">
      <xs:selector xpath=".//mstns:Table1" />
      <xs:field xpath="mstns:id" />
    </xs:unique>
    <xs:unique name="Dataset1Key1" msdata:PrimaryKey="true">
      <xs:selector xpath=".//mstns:venue_seats" />
      <xs:field xpath="mstns:venue_id" />
    </xs:unique>
    <xs:keyref name="Table1venue_seats" refer="Dataset1Key2">
      <xs:selector xpath=".//mstns:venue_seats" />
      <xs:field xpath="mstns:seat_id" />
    </xs:keyref>
    <xs:keyref name="venue_seatsTable1" refer="Dataset1Key1" 
msdata:IsNested="true">
      <xs:selector xpath=".//mstns:Table1" />
      <xs:field xpath="mstns:id" />
    </xs:keyref>
  </xs:element>
</xs:schema>
============================================

Please have a try to see whether it helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no 
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx








transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent