Friday, February 24, 2012

Capturing ALL elements and attributes

Hi
I need to capture and store the data from the following xml file:
- <server name="xxx-abcd">
- <match matchno="1">
<fullkey>99</fullkey>
<key>99</key>
<type>99</type>
<value>29</value>
</match>
- <match matchno="2">
<fullkey>87</fullkey>
<key>87</key>
<type>87</type>
<value>46</value>
</match>
- <match matchno="3">
<fullkey>52</fullkey>
<key>52</key>
<type>52</type>
<value>-12</value>
</match>
Using the following schema I can insert everything except the first
line <server name="xxx-abcd">
which I would like to do for each row so that it inserts the following
into my table
e.g
name matchno fullkey key type value
xxx-abcd 1 99 99 99 29
xxx-abcd 2 87 87 87 46
xxx-abcd 3 52 52 52 12
- <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
- <xsd:element name="match" sql:relation="cpl">
- <xsd:complexType>
- <xsd:sequence>
<xsd:element name="fullkey" type="xsd:integer" />
<xsd:element name="key" type="xsd:string" />
<xsd:element name="type" type="xsd:string" />
<xsd:element name="value" type="xsd:string" />
</xsd:sequence>
<xsd:attribute name="matchno" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
What changes do I need to make to my schema (above) to be able to do
this please?
Thanks in advance to anyone who replies!
Regards
Chris
Assume this is SQL 2000 and SQLXML you're using? If on SQL 2005 there's a
much easier way to achieve the same result with the XML data type .value()
and .nodes() methods.
<templeoakchris@.hotmail.com> wrote in message
news:1171569947.901469.306050@.j27g2000cwj.googlegr oups.com...
> Hi
> I need to capture and store the data from the following xml file:
> - <server name="xxx-abcd">
> - <match matchno="1">
> <fullkey>99</fullkey>
> <key>99</key>
> <type>99</type>
> <value>29</value>
> </match>
> - <match matchno="2">
> <fullkey>87</fullkey>
> <key>87</key>
> <type>87</type>
> <value>46</value>
> </match>
> - <match matchno="3">
> <fullkey>52</fullkey>
> <key>52</key>
> <type>52</type>
> <value>-12</value>
> </match>
>
> Using the following schema I can insert everything except the first
> line <server name="xxx-abcd">
> which I would like to do for each row so that it inserts the following
> into my table
> e.g
> name matchno fullkey key type value
> xxx-abcd 1 99 99 99 29
> xxx-abcd 2 87 87 87 46
> xxx-abcd 3 52 52 52 12
>
> - <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
> - <xsd:element name="match" sql:relation="cpl">
> - <xsd:complexType>
> - <xsd:sequence>
> <xsd:element name="fullkey" type="xsd:integer" />
> <xsd:element name="key" type="xsd:string" />
> <xsd:element name="type" type="xsd:string" />
> <xsd:element name="value" type="xsd:string" />
> </xsd:sequence>
> <xsd:attribute name="matchno" type="xsd:string" />
> </xsd:complexType>
> </xsd:element>
> </xsd:schema>
> What changes do I need to make to my schema (above) to be able to do
> this please?
> Thanks in advance to anyone who replies!
> Regards
> Chris
>
|||On 15 Feb, 21:48, "Mike C#" <x...@.xyz.com> wrote:
> Assume this is SQL 2000 and SQLXML you're using? If on SQL 2005 there's a
> much easier way to achieve the same result with the XML data type .value()
> and .nodes() methods.
> <templeoakch...@.hotmail.com> wrote in message
> news:1171569947.901469.306050@.j27g2000cwj.googlegr oups.com...
>
>
>
>
>
>
>
> - Show quoted text -
Oops... yes, I am using SQL 2000 and SQLXML ... any ideas?
Regards
Chris
|||>
> Oops... yes, I am using SQL 2000 and SQLXML ... any ideas?
> Regards
> Chris
>
Sorry, it's been far too long since I did anything with SQLXML on 2000. I
did notice your XML is not well-formed (no closing </server>). You might
want to look up the "sql:field" attribute at microsoft.com. You will
probably need to expand your XSD schema to include an outer "server" element
something like this (not tested):
...xsd:schema...
<xsd:element name="server">
<xsd:complexType>
<xsd:sequence>
...existing schema "match" element...
<xsd:attribute name="name" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
You will probably need to play with the sql:relation and sql:field
attributes a bit as well.
Sorry couldn't be of more help.

No comments:

Post a Comment