Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - RE: help with selectSingleNode >Thread Next - Re: help with selectSingleNode Re: help with selectSingleNodeTo: NULL Date: 6/3/2004 8:24:00 AM It looks like your selectSingleNode() call is using an absolute path, that
is, it references xs:element starting at the top level, xs:schema.
Is there a way to find the xs:sequence element relative to the current node?
Thanks for our help.
C.
I'm using msxml 3 and up, btw.
> 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
>
>
>
>
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
