This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > March 2004 > 'selectSingleNode' returns NULL if XML-Data schema is assigned???
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
'selectSingleNode' returns NULL if XML-Data schema is assigned???
|
|
| Teis Draiby 2004-03-30, 10:13 pm |
| Why can't I use 'selectSingleNode' when a XML-Data schema is assigned my XML
document? (see XML #1). selectSingleNode returns NULL in this case.
BUT: selectSingleNode works fine if I remove the reference to the schema
(see XML #2).
I validated the XML file against the schema in XMLSPY.
Im using VC++ and MSXML 4.0
thank you very much, Teis
I use: ...selectSingleNode("//weather/degrees");
XML #1 with schema:
---------------------------------------
<?xml version="1.0"?>
<weather xmlns="x-schema:weatherSchema.xml">
<degrees>67.5</degrees>
</weather>
XML #2 without schema:
---------------------------------------
<?xml version="1.0"?>
<weather>
<degrees>67.5</degrees>
</weather>
Schema: "weatherSchema.xml"
---------------------------------------
<Schema xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="degrees" content="textOnly" dt:type="float"/>
<ElementType name="weather" content="eltOnly">
<element type="degrees"/>
</ElementType>
</Schema>
| |
| Gohlool 2004-03-30, 10:13 pm |
| HIi!
If I am not wrong you have to use the followings:
there are 2 ways:
1) the correct way
using the XMLSchemaCache to add your schema to!
example:
SchemaCollection := CoXMLSchemaCache40.Create;
SchemaCollection.validateOnLoad := true;
SchemaCollection.add('', 'c:\weatherSchema.xml'); //the first Param. is the
prefix, but in your case you have no prefix defined.
and then
in you IXMLDomDocument2
XMLDoc.schemas := SchemaCollection;
XMLDoc.setProperty('NewParser', 'True');
XMLDoc.setProperty('SelectionLanguage', 'XPath');
then I think you will need the following:
XMLDoc.setProperty('SelectionNamespaces', NameSpaceList);
check the Help and you will see what is the SelectionNamespaces property is!
I think in your case it would be something like this
NameSpaceList := 'xmlns="urn:schemas-microsoft-com:xml-data" ';
Result.setProperty('SelectionNamespaces', NameSpaceList);
then you have to validate your xml
XMLDOc.validateOnParse := True;
and then try the your selectSingleNode("//weather/degrees"); again
I think this should help!
2) the simple hack. (because you don't have any other namespaces and tags
with the same name)
the other way is the following:
forget all what I wrote before:
now go to your code and instead of calling:
selectSingleNode("//weather/degrees");
call something like this:
SelectionString = "descendant::*[local-name()='//weather/degrees']";
selectSingleNode(SelectionString);
good luck!
Gohlool
"Teis Draiby" <teisREMOVE-THIS@draiby.com> wrote in message
news:OMSSjxSEEHA.3424@tk2msftngp13.phx.gbl...
> Why can't I use 'selectSingleNode' when a XML-Data schema is assigned my
XML
> document? (see XML #1). selectSingleNode returns NULL in this case.
> BUT: selectSingleNode works fine if I remove the reference to the schema
> (see XML #2).
> I validated the XML file against the schema in XMLSPY.
>
> Im using VC++ and MSXML 4.0
>
> thank you very much, Teis
>
>
>
> I use: ...selectSingleNode("//weather/degrees");
>
>
>
> XML #1 with schema:
> ---------------------------------------
> <?xml version="1.0"?>
> <weather xmlns="x-schema:weatherSchema.xml">
> <degrees>67.5</degrees>
> </weather>
>
>
>
> XML #2 without schema:
> ---------------------------------------
> <?xml version="1.0"?>
> <weather>
> <degrees>67.5</degrees>
> </weather>
>
>
>
> Schema: "weatherSchema.xml"
> ---------------------------------------
> <Schema xmlns="urn:schemas-microsoft-com:xml-data"
> xmlns:dt="urn:schemas-microsoft-com:datatypes">
> <ElementType name="degrees" content="textOnly" dt:type="float"/>
> <ElementType name="weather" content="eltOnly">
> <element type="degrees"/>
> </ElementType>
> </Schema>
>
>
>
>
| |
| Teis Draiby 2004-03-30, 10:14 pm |
| Hi Gohlool,
thank you very much for your answer! It's complaining about your simple hack
so now I'm experimenting with 'the correct way'.
Meanwhile: I'm wondering why I don't need all this if I parse a XSD
document.
What is the difference?
Thank you very much, Teis
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|