Thursday, March 8, 2012

about WITH XMLNAMESPACES

Hello experts!
I'm using a table including one column declared as xml-datatype.
This table holds instances of xml-documents, that use one of two schemas.
Let's call them schema1 and schema2, where schema1 is Version 1 of the
schema, and schema2 the extended Version 2.
Version 2 holds everything of Version 1 in the same structure, but allowes
some more fields.
The table has the following fields:
keyfield
schemaversion
xmldata
I now want to create a view, where the customer could easily access the data
inside the xml.
My idea was a view like
WITH XMLNAMESPACES(DEFAULT 'xmlns1')
SELECT ...
FROM ...
WHERE schemaversion = 1
UNION
WITH XMLNAMESPACES(DEFAULT 'xmlns2')
SELECT ...
FROM ...
WHERE schemaversion = 2
But the second WITH-statement seems to be unsupported.
Has anyone of you an idea, how i could access based on both schemas?
Thanks very much!
Maxok, i found some kind of workaround.
i created two views on the table, on using the namespace of schema1 and the
other of schema2.
every view includes a where clause on the data to only process the rows it
has to.
finally i created a third view which creates a union of the other two views
and which is the "interface" to the customer.
hmm, at the moment, as i do not have very much data to test on, the speed
seems to be satisfying, but i wonder how this will change if i get more and
more data.
so, if anyone of you has another idea, please share it!
thanks!
max
"Markus Emayr" <essmayr/at/racon-linz.at> schrieb im Newsbeitrag
news:uqwa2qrHHHA.1248@.TK2MSFTNGP03.phx.gbl...
> Hello experts!
> I'm using a table including one column declared as xml-datatype.
> This table holds instances of xml-documents, that use one of two schemas.
> Let's call them schema1 and schema2, where schema1 is Version 1 of the
> schema, and schema2 the extended Version 2.
> Version 2 holds everything of Version 1 in the same structure, but allowes
> some more fields.
> The table has the following fields:
> keyfield
> schemaversion
> xmldata
> I now want to create a view, where the customer could easily access the
> data inside the xml.
> My idea was a view like
> WITH XMLNAMESPACES(DEFAULT 'xmlns1')
> SELECT ...
> FROM ...
> WHERE schemaversion = 1
> UNION
> WITH XMLNAMESPACES(DEFAULT 'xmlns2')
> SELECT ...
> FROM ...
> WHERE schemaversion = 2
> But the second WITH-statement seems to be unsupported.
> Has anyone of you an idea, how i could access based on both schemas?
> Thanks very much!
> Max
>|||Why not use a prefix for each and declare it in a single with statement:
WITH XMLNAMESPACES('xmlns1' as "s1", 'xmlns2' as "s2")
SELECT ...
FROM ...
WHERE schemaversion = 1
UNION
SELECT ...
FROM ...
WHERE schemaversion = 2
Best regards
Michael
"Markus Emayr" <essmayr/at/racon-linz.at> wrote in message
news:uqwa2qrHHHA.1248@.TK2MSFTNGP03.phx.gbl...
> Hello experts!
> I'm using a table including one column declared as xml-datatype.
> This table holds instances of xml-documents, that use one of two schemas.
> Let's call them schema1 and schema2, where schema1 is Version 1 of the
> schema, and schema2 the extended Version 2.
> Version 2 holds everything of Version 1 in the same structure, but allowes
> some more fields.
> The table has the following fields:
> keyfield
> schemaversion
> xmldata
> I now want to create a view, where the customer could easily access the
> data inside the xml.
> My idea was a view like
> WITH XMLNAMESPACES(DEFAULT 'xmlns1')
> SELECT ...
> FROM ...
> WHERE schemaversion = 1
> UNION
> WITH XMLNAMESPACES(DEFAULT 'xmlns2')
> SELECT ...
> FROM ...
> WHERE schemaversion = 2
> But the second WITH-statement seems to be unsupported.
> Has anyone of you an idea, how i could access based on both schemas?
> Thanks very much!
> Max
>

No comments:

Post a Comment