I am having problems with the namespaces when using XML type data
inside a for XMLpath..
here is the first example
----
--
WITH XMLNAMESPACES(DEFAULT 'http://www.ratdog.com/example' )
select
'karl' as "name",
(select
'1' as "mine/one",
'2' as "mine/two"
for xml path('child'), type
)
for xml path('outer'), type
----
<outer xmlns="http://www.ratdog.com/example">
<name>karl</name>
<child xmlns="http://www.ratdog.com/example">
<mine>
<one>1</one>
<two>2</two>
</mine>
</child>
</outer>
----
you'll notice that it added the namespace to the "inner child" :),
which i'd rather it not do but at least its correct and it works.
however in the following example i put the "inner child" sql inside a
function as show :
----
create function dbo.testfunc()
returns XML
as
begin
return
(
select
'1' as "mine/one",
'2' as "mine/two"
for xml path('child'), type
)
end
WITH XMLNAMESPACES(DEFAULT 'http://www.ratdog.com/example' )
select
'karl' as "name",
dbo.testfunc()
for xml path('outer'), type
---
<outer xmlns="http://www.ratdog.com/example">
<name>karl</name>
<child xmlns="">
<mine>
<one>1</one>
<two>2</two>
</mine>
</child>
</outer>
---
and it puts the namespace as "", which i definately don't want.. i
don't want that clause in there at all
how can i get rid of it? or achieve a suitable workaround.
KarlNote that the function creates a document that has no namespace associated
with it. Since you include it in one that has the prefix, we have to
undeclare the default prefix.
So if you want to have the function have the same default namespace, you
need to use the WITH clause in the function.
And no, we currently do not remove the declarations on the inner level if
they are redundant...
Best regards
Michael
<klumsy@.xtra.co.nz> wrote in message
news:1144364933.977174.287100@.u72g2000cwu.googlegroups.com...
> I am having problems with the namespaces when using XML type data
> inside a for XMLpath..
> here is the first example
> ----
--
> WITH XMLNAMESPACES(DEFAULT 'http://www.ratdog.com/example' )
> select
> 'karl' as "name",
> (select
> '1' as "mine/one",
> '2' as "mine/two"
> for xml path('child'), type
> )
> for xml path('outer'), type
> ----
> <outer xmlns="http://www.ratdog.com/example">
> <name>karl</name>
> <child xmlns="http://www.ratdog.com/example">
> <mine>
> <one>1</one>
> <two>2</two>
> </mine>
> </child>
> </outer>
> ----
> you'll notice that it added the namespace to the "inner child" :),
> which i'd rather it not do but at least its correct and it works.
> however in the following example i put the "inner child" sql inside a
> function as show :
> ----
> create function dbo.testfunc()
> returns XML
> as
> begin
> return
> (
> select
> '1' as "mine/one",
> '2' as "mine/two"
> for xml path('child'), type
> )
> end
> WITH XMLNAMESPACES(DEFAULT 'http://www.ratdog.com/example' )
> select
> 'karl' as "name",
> dbo.testfunc()
> for xml path('outer'), type
> ---
> <outer xmlns="http://www.ratdog.com/example">
> <name>karl</name>
> <child xmlns="">
> <mine>
> <one>1</one>
> <two>2</two>
> </mine>
> </child>
> </outer>
> ---
> and it puts the namespace as "", which i definately don't want.. i
> don't want that clause in there at all
> how can i get rid of it? or achieve a suitable workaround.
> Karl
>
Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts
Thursday, March 8, 2012
Chicken or Egg, XML or XSD
What comes first, XML or XSD? When you start building a project that
will include XML, what would you start on first, building your XML data
file or your XSD schema file?
thanks
Ralph Krausse
www.consiliumsoft.com
Use the START button? Then you need CSFastRunII...
A new kind of application launcher integrated in the taskbar!
ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
To a large extent, it probably depends on what you're going to do with the
data. Generally though. I'd be inclined to go with XSD first, since that
defines the data model - in the same way that you design a database schema
before doing any INSERT statements. Having said that, I usually go through a
kind of iterative process (for both database design and XML modelling) where
I start with an XML structure (or entity model) on paper that I know is
"kinda" what I need, and then start working out the XSD / table defs needed
for that structure. I then need to think about the various constraints,
relationships, hierarchies etc. and refine the schema from there.
So, to sum up - the answer to your question is both :-)
Of course, somethimes your just given a schema that you have to work with
(e.g. when integrating with external partners or existing systems), so the
choice goes out the window anyway!
Someone else might have a more "formal design methodology" type answer - any
takers!
Cheers,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
"msnews.microsoft.com" <no@.no.com> wrote in message
news:%23Hw5kwOkEHA.2680@.TK2MSFTNGP15.phx.gbl...
What comes first, XML or XSD? When you start building a project that
will include XML, what would you start on first, building your XML data
file or your XSD schema file?
thanks
Ralph Krausse
www.consiliumsoft.com
Use the START button? Then you need CSFastRunII...
A new kind of application launcher integrated in the taskbar!
ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
|||It really depends on the application scenario.
Often, when dealing with interop scenarios, a schema is given apriori. Thus
you start with the schema.
However, one of the strengths of XML is that you can apply XSD late for
validation and apply more than one XSD for a given XML instance (to check
for different constraints). So sometimes, you may start with XML in one
place and with XSD in another, have more than one XSD developed first etc.
Sometimes if devloping markup, you may start with a small instance and
define the schema and instance iteratively.
Sometimes, you do not need (or cannot preview) a schema at all since your
XML may be very dynamic. Sometimes the data already exists and you want to
infer a schema.
I don't think that there should be a one-fit-all solution, but for many data
and document interop scenarios and database design scenarios, starting with
the schema(ta) is often a better way to understand the data.
Best regards
Michael
"Graeme Malcolm" <graemem_cm@.hotmail.com> wrote in message
news:uFrcmQPkEHA.3724@.TK2MSFTNGP11.phx.gbl...
> To a large extent, it probably depends on what you're going to do with the
> data. Generally though. I'd be inclined to go with XSD first, since that
> defines the data model - in the same way that you design a database schema
> before doing any INSERT statements. Having said that, I usually go through
> a
> kind of iterative process (for both database design and XML modelling)
> where
> I start with an XML structure (or entity model) on paper that I know is
> "kinda" what I need, and then start working out the XSD / table defs
> needed
> for that structure. I then need to think about the various constraints,
> relationships, hierarchies etc. and refine the schema from there.
> So, to sum up - the answer to your question is both :-)
> Of course, somethimes your just given a schema that you have to work with
> (e.g. when integrating with external partners or existing systems), so the
> choice goes out the window anyway!
> Someone else might have a more "formal design methodology" type answer -
> any
> takers!
> Cheers,
> Graeme
> --
> --
> Graeme Malcolm
> Principal Technologist
> Content Master Ltd.
> www.contentmaster.com
>
> "msnews.microsoft.com" <no@.no.com> wrote in message
> news:%23Hw5kwOkEHA.2680@.TK2MSFTNGP15.phx.gbl...
> What comes first, XML or XSD? When you start building a project that
> will include XML, what would you start on first, building your XML data
> file or your XSD schema file?
> thanks
> Ralph Krausse
> www.consiliumsoft.com
> Use the START button? Then you need CSFastRunII...
> A new kind of application launcher integrated in the taskbar!
> ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
>
>
|||Hello Ralph,
Do you have any more concerns on the reply? If there is any question,
please feel free to post here and we will follow up.
Thanks very much.
Best regards,
Yanhong Huang
Microsoft Community Support
Get Secure! C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn
This posting is provided "AS IS" with no warranties, and confers no rights.
will include XML, what would you start on first, building your XML data
file or your XSD schema file?
thanks
Ralph Krausse
www.consiliumsoft.com
Use the START button? Then you need CSFastRunII...
A new kind of application launcher integrated in the taskbar!
ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
To a large extent, it probably depends on what you're going to do with the
data. Generally though. I'd be inclined to go with XSD first, since that
defines the data model - in the same way that you design a database schema
before doing any INSERT statements. Having said that, I usually go through a
kind of iterative process (for both database design and XML modelling) where
I start with an XML structure (or entity model) on paper that I know is
"kinda" what I need, and then start working out the XSD / table defs needed
for that structure. I then need to think about the various constraints,
relationships, hierarchies etc. and refine the schema from there.
So, to sum up - the answer to your question is both :-)
Of course, somethimes your just given a schema that you have to work with
(e.g. when integrating with external partners or existing systems), so the
choice goes out the window anyway!
Someone else might have a more "formal design methodology" type answer - any
takers!
Cheers,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
"msnews.microsoft.com" <no@.no.com> wrote in message
news:%23Hw5kwOkEHA.2680@.TK2MSFTNGP15.phx.gbl...
What comes first, XML or XSD? When you start building a project that
will include XML, what would you start on first, building your XML data
file or your XSD schema file?
thanks
Ralph Krausse
www.consiliumsoft.com
Use the START button? Then you need CSFastRunII...
A new kind of application launcher integrated in the taskbar!
ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
|||It really depends on the application scenario.
Often, when dealing with interop scenarios, a schema is given apriori. Thus
you start with the schema.
However, one of the strengths of XML is that you can apply XSD late for
validation and apply more than one XSD for a given XML instance (to check
for different constraints). So sometimes, you may start with XML in one
place and with XSD in another, have more than one XSD developed first etc.
Sometimes if devloping markup, you may start with a small instance and
define the schema and instance iteratively.
Sometimes, you do not need (or cannot preview) a schema at all since your
XML may be very dynamic. Sometimes the data already exists and you want to
infer a schema.
I don't think that there should be a one-fit-all solution, but for many data
and document interop scenarios and database design scenarios, starting with
the schema(ta) is often a better way to understand the data.
Best regards
Michael
"Graeme Malcolm" <graemem_cm@.hotmail.com> wrote in message
news:uFrcmQPkEHA.3724@.TK2MSFTNGP11.phx.gbl...
> To a large extent, it probably depends on what you're going to do with the
> data. Generally though. I'd be inclined to go with XSD first, since that
> defines the data model - in the same way that you design a database schema
> before doing any INSERT statements. Having said that, I usually go through
> a
> kind of iterative process (for both database design and XML modelling)
> where
> I start with an XML structure (or entity model) on paper that I know is
> "kinda" what I need, and then start working out the XSD / table defs
> needed
> for that structure. I then need to think about the various constraints,
> relationships, hierarchies etc. and refine the schema from there.
> So, to sum up - the answer to your question is both :-)
> Of course, somethimes your just given a schema that you have to work with
> (e.g. when integrating with external partners or existing systems), so the
> choice goes out the window anyway!
> Someone else might have a more "formal design methodology" type answer -
> any
> takers!
> Cheers,
> Graeme
> --
> --
> Graeme Malcolm
> Principal Technologist
> Content Master Ltd.
> www.contentmaster.com
>
> "msnews.microsoft.com" <no@.no.com> wrote in message
> news:%23Hw5kwOkEHA.2680@.TK2MSFTNGP15.phx.gbl...
> What comes first, XML or XSD? When you start building a project that
> will include XML, what would you start on first, building your XML data
> file or your XSD schema file?
> thanks
> Ralph Krausse
> www.consiliumsoft.com
> Use the START button? Then you need CSFastRunII...
> A new kind of application launcher integrated in the taskbar!
> ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
>
>
|||Hello Ralph,
Do you have any more concerns on the reply? If there is any question,
please feel free to post here and we will follow up.
Thanks very much.
Best regards,
Yanhong Huang
Microsoft Community Support
Get Secure! C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn
This posting is provided "AS IS" with no warranties, and confers no rights.
Subscribe to:
Posts (Atom)