Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Saturday, February 25, 2012

Designing "XML Proof" databases?

Hello All,
I'm fairly new to the XML game. I am designing a database that will contain
online books. Each book will be broken into parts, each part into chapters,
each chapter into sections, each section into... you get the idea. I think
this is the perfect opportunity for the XML data type in Yukon. However, I
did to put this database together in the next few weeks.
My question is whether there are any best practices for designing
traditional heirarchical databases today that will smoothly transition into
an XML future. (Books, articles, suggestions here, etc.?)
I need to have each text snippet as it's own record in one table (snippetID,
title, body, etc.) I was thinking that I would create a second table for the
heirarchy itself where I would maintain the relationships tied back to the
specific snippetID's. My plan was to use SQLXML to represent the data as XML
(which I think could drive a cool DHTML menu). But, I wonder if this is the
right approach given that yukon is around the corner (yet that I need this
before Yukon's release date?)
Thanks so much,
Brian
What do you do with the data once it is stored in the database?
Do you store and retrieve the document as a whole? In that case, I would
keep the document as an NTEXT or TEXT field depending on the encoding of the
XML and propagate some lookup info into other columns. This will be easily
converted into the XML datatype.
If you are planning on doing extensive reshaping and or selecting only
parts, you may want to partition the XML into separate components and then
do the same as above...
Best regards
Michael
"Brian Madden" <brian@.brianmadden.com> wrote in message
news:uF2NsxF3EHA.1396@.tk2msftngp13.phx.gbl...
> Hello All,
> I'm fairly new to the XML game. I am designing a database that will
> contain online books. Each book will be broken into parts, each part into
> chapters, each chapter into sections, each section into... you get the
> idea. I think this is the perfect opportunity for the XML data type in
> Yukon. However, I did to put this database together in the next few weeks.
> My question is whether there are any best practices for designing
> traditional heirarchical databases today that will smoothly transition
> into an XML future. (Books, articles, suggestions here, etc.?)
> I need to have each text snippet as it's own record in one table
> (snippetID, title, body, etc.) I was thinking that I would create a second
> table for the heirarchy itself where I would maintain the relationships
> tied back to the specific snippetID's. My plan was to use SQLXML to
> represent the data as XML (which I think could drive a cool DHTML menu).
> But, I wonder if this is the right approach given that yukon is around the
> corner (yet that I need this before Yukon's release date?)
> Thanks so much,
> Brian
>

Friday, February 24, 2012

Design Time XSD Metadata refresh

My SSIS package has 19 XML Source inputs constructed of 4 different (XSD) Schemas. I'm trying to find a convenient way to refresh the underlying metadata at design time so that I don't have to open each XML Source, change the XSD reference, click on the columns display, change the XSD back to the original but updated XSD just to get say a new default column width for string data. Does anyone have a quicker way to force an SSIS package to pick up changes in a referenced XSD?

Unfortunately, there is no an easy way to do this. Maybe the easiest would be to do this programmatically.

See the following thread for more details:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2073404&SiteID=1

Thanks,

Bob

Sunday, February 19, 2012

Design Question - Is Integration Services the way to go ?

we need to transfer data from a OLTP SQL 2005 database to the backend OLAP Datamart and Datawarehouse databases. This data is a long string of XML (from Infopath), out of which we need to extract the data values and populate the Datamart and datawarehouse. Ideally this will be an automated process - and will also have the flexibility to cater for changes in the xml structur.

we would also like the Analysis services cubes to be "updated" in real-time as the transfer occurs.

is Integration Services the way to go ?

You have a lot of choices here. I would recommend starting out by investigating the XML methods you have in SQL Server in general. Paste this link in Books Online in the "URL" bar:

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/63cbe6c9-79d0-4cf3-b451-36dbe4668bf6.htm

Without knowing more, I think SSIS is the way to go for you, but that depends a great deal on whether you are "trickling" the data or loading it in one pass periodically. SSIS gives you a lot of flexibility and functionality, but there is a learning curve with it. That being said, I think it's worth the effort. Spending a little more time getting a package together and documenting it well is a great way to implement your solution in SSIS.

Buck Woody

http://www.buckwoody.com

|||

Buck

thx for this

the destination datamart stores the latest version of the case (i.e. the latest record), the destination datawarehouse stores all of the versions of the case (i.e. all records). Ideally we would be updating both of these records at the same time in real-time "trickling" mode - but if necessary, we could bulk the warehouse updates to (for example) an hourly process.

also need to consider the analysis services part - we are using analysis services cubes for our reporting - and would need these to also be updated in real-time (or bulk upload if required on the datawarehouse database) - is this easily done within SSIS ?

also - alternatives... have considered a couple of alternatives

might SQLCLR code done as a trigger on the required table be an alternative solution ? - how would this perform in comparison to the possible SSIS solution ?

amending the web service that does the update of the OLTP table to also do the update of the datamart / datawharehouse ? (not so keen on this one as we are trying to separate these out ?)

thx

mark


|||

The performance questions you have would have to be tested - there are just too many variables to say one way or another.

The bigger question is how your Analysis system will be used. If you need "real-time" information, then trickling is the way to go, and I'd recommend using an HTTP endpoint or one of the other XML methods native to SQL Server, or perhaps the CLR route you've mentioned if the business logic should be coded in.

If your analysis is truly strategic (based on this data, should we make hubcaps or aircraft parts), then SSIS is my recommendation. Strategic decisions aren't made multiple times a day, so a bulk load process is better tolerated. In either case you will transform "in-flight", meaning you don't have to stage the data, so you save a lot of resources and time.

And in answer to your question about cubes, yes, SSIS is suited for that. In fact, it has many steps and processes built right in specific to AS.

Tuesday, February 14, 2012

Deserialize xml data from sql 2005

We're having a hard time with SQL 05's xml.
In a nutshell, I have a schema. I have used .Net 2.0's xsd tool to create classes from this schema.

This schema is also tied to a XML column in my database server. So far so good.

However, when I go to deserialize the xml data stored in the database server I'm getting inconsistent results. Namely the differences in the following queries:
SELECT LoanXML.query('declare namespace MISMO="http://mrgdev.local/mismo/";//MISMO:LOAN')
FROM Loans
WHERE Loans.InternalID = @.LoanID

returns something completely different from:
SELECT LoanXML from Loans where InternalID = @.LoanID

The difference is that the first query throws xsi:nil=true into EVERY SINGLE NODE. Whereas the second one doesn't.

When we go to deserialize, then the nodes aren't converting into objects even though they are properly filled out...

I'd just chuck the .query syntax, except for a little problem where I'm trying to return just the node(s) I want instead of the whole thing.

Is there anyone else using xml deserialization with SQL 05?<xs:schema

xmlns:xs="http://www.w3.org/2001/XMLSchema"

xmlns="http://mrgdev.local/mismo/"

targetNamespace="http://mrgdev.local/mismo/"

elementFormDefault="qualified">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation=".\xml.xsd"/>
<xs:element name="LOAN" nillable="false">
<xs:complexType>
<xs:sequence>
<xs:element name="_APPLICATION" nillable="true" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="_DATA_INFORMATION" nillable="true" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element ref="DATA_VERSION"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="DATA_VERSION" nillable="true">
<xs:complexType>
<xs:attribute name="_Name" type="xs:string" use="required"/>
<xs:attribute name="_Number" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>|||CREATE XML SCHEMA COLLECTION [dbo].[ChrisSchema]
AS N'<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://mrgdev.local/test/"
xmlns:dv="http://mrgdev.local/DV/"
targetNamespace="http://mrgdev.local/test/" elementFormDefault="qualified">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation=".\xml.xsd"/>
<xs:element name="LOAN" nillable="false">
<xs:complexType>
<xs:sequence>
<xs:element name="_APPLICATION" nillable="true" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="_DATA_INFORMATION" nillable="true" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element ref="DATA_VERSION"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="DATA_VERSION" nillable="true">
<xs:complexType>
<xs:attribute name="_Name" type="xs:string" use="required"/>
<xs:attribute name="_Number" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
'|||The following creates a table and inserts a row with xml data into it.

CREATE TABLE [dbo].[MyTest](
[id] [uniqueidentifier] NOT NULL CONSTRAINT [DF_mytest_id] DEFAULT (newid()),
[test] [xml](CONTENT [dbo].[ChrisSchema]) NULL,
CONSTRAINT [PK_chris] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

insert into MyTest(test)
values('<LOAN xmlns="http://mrgdev.local/test/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mrgdev.local/test/">
<_APPLICATION>
<_DATA_INFORMATION>
<DATA_VERSION _Name="DVTESt" _Number="123123"/>
</_DATA_INFORMATION>
</_APPLICATION>
</LOAN>')|||Now, execute

SELECT test.query('declare namespace test="http://mrgdev.local/test/";//test:LOAN')
FROM MyTest

You're result will be:

<LOAN xmlns="http://mrgdev.local/test/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mrgdev.local/test/">
<_APPLICATION>
<_DATA_INFORMATION>
<DATA_VERSION _Name="DVTESt" _Number="123123" xsi:nil="true" />
</_DATA_INFORMATION>
</_APPLICATION>
</LOAN>

Notice the xsi:nil=true... First off, that's wrong. It isn't nil. Second, this will not deserialize. WTF?|||If I just run

select test from MyTest

then the data looks like:

<LOAN xmlns="http://mrgdev.local/test/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mrgdev.local/test/">
<_APPLICATION>
<_DATA_INFORMATION>
<DATA_VERSION _Name="DVTESt" _Number="123123" />
</_DATA_INFORMATION>
</_APPLICATION>
</LOAN>

In this case the data_version node correctly comes back WITHOUT the xsi:nil="true"
In addition, if we UNTYPE the xml column, then it will also come back without the xsi:nil="true"garbage; but that's not a real option.

How do we get the typed version to not do this? I even tried placing the definition for DATA_VERSION in a different schema, but this had zero effect on our output.|||After all of our testing, it appears that if an element only has attributes then it reports the element as xsi:nil="true" which in our case is wrong, because our elements only have attributes.

Is there some way to get around this?