Sunday, February 19, 2012

how to filter element by attribute to be imported using SQLXML schema annotation in XML Bu

[question 1]
does anyone know how to filter the element by attribute to be imported
using SQLXML annotation?
for example, in the following xml, I only want to import the value in
the element with attribute Type="shipping" only, not the one with
attribute Type="billing". is it possible to use annotation to filter
that?
<Addresses>
<Address Type="shipping">1234 shipping avenue</Address>
<Address Type="billing">5678 billing street</Address>
</Addresses>
[question 2]
This question is kind of related too. I'd like to write schema
annotaion that's both "element-centric" and "attribute-centric".
for example, in the the following xml, I need to upload both the value
in attribute CustID and also the value in element Customer.
<Customers>
<Customer CustID="1">Customer One</Customer>
<Customer CustID="2">Customer Two</Customer>
</Customers>
I've thought about using other approaches but XML Bulk Load should be
the ideal way for performance reason because our XML files are all
very big, more than 100MB. But we're stuck on the schema annotaion.
any idea you may have is greatly appreciated.
The short answer to Q1 is "no" I'm afraid. You could however use an XSLT
stylesheet to filter the data first, and then import the filtered data. The
XPath expression you need in the stylesheet is something like
"/Addresses[Address/@.Type='shipping']"
As for Q2, if the element/attribute names match the table/column names you
can actually get away without using a schema and both element-centric and
attribute-centric mappings will work by default. If the names are different
however, this won't work. Again, an XSLT stylesheet prior to bulk loading
would be the way to go here.
There's an example of using an XSLT stylesheet on sqlxml.org at
http://sqlxml.org/faqs.aspx?faq=49
Cheers,
Graeme
Graeme Malcolm
Principal Technologist
Content Master Ltd.
"Evangeline" <evangeli@.yahoo.com> wrote in message
news:df3f63cc.0403282343.883270d@.posting.google.co m...
> [question 1]
> does anyone know how to filter the element by attribute to be imported
> using SQLXML annotation?
> for example, in the following xml, I only want to import the value in
> the element with attribute Type="shipping" only, not the one with
> attribute Type="billing". is it possible to use annotation to filter
> that?
> <Addresses>
> <Address Type="shipping">1234 shipping avenue</Address>
> <Address Type="billing">5678 billing street</Address>
> </Addresses>
>
> [question 2]
> This question is kind of related too. I'd like to write schema
> annotaion that's both "element-centric" and "attribute-centric".
>
> for example, in the the following xml, I need to upload both the value
> in attribute CustID and also the value in element Customer.
> <Customers>
> <Customer CustID="1">Customer One</Customer>
> <Customer CustID="2">Customer Two</Customer>
> </Customers>
>
>
> I've thought about using other approaches but XML Bulk Load should be
> the ideal way for performance reason because our XML files are all
> very big, more than 100MB. But we're stuck on the schema annotaion.
>
> any idea you may have is greatly appreciated.
|||1) No, I'm afraid you can't do that. As otherwise suggested, you could run
an XSLT first to remove the data you don't want.
2) You should be able to map this by annotating the element with the name of
the column you want it to go to and the attribute with the name of the
column you want it to go to.
Irwin Dolobowsky
Program Manager - SqlXml
http://weblogs.asp.net/irwando
This posting is provided "AS IS" with no warranties, and confers no rights.
"Evangeline" <evangeli@.yahoo.com> wrote in message
news:df3f63cc.0403282343.883270d@.posting.google.co m...
> [question 1]
> does anyone know how to filter the element by attribute to be imported
> using SQLXML annotation?
> for example, in the following xml, I only want to import the value in
> the element with attribute Type="shipping" only, not the one with
> attribute Type="billing". is it possible to use annotation to filter
> that?
> <Addresses>
> <Address Type="shipping">1234 shipping avenue</Address>
> <Address Type="billing">5678 billing street</Address>
> </Addresses>
>
> [question 2]
> This question is kind of related too. I'd like to write schema
> annotaion that's both "element-centric" and "attribute-centric".
>
> for example, in the the following xml, I need to upload both the value
> in attribute CustID and also the value in element Customer.
> <Customers>
> <Customer CustID="1">Customer One</Customer>
> <Customer CustID="2">Customer Two</Customer>
> </Customers>
>
>
> I've thought about using other approaches but XML Bulk Load should be
> the ideal way for performance reason because our XML files are all
> very big, more than 100MB. But we're stuck on the schema annotaion.
>
> any idea you may have is greatly appreciated.
|||Thank you very much for your help.
I was trying to avoid using xslt because it adds too much overhead to the process.
for example, I'm using MSXML3 object to transform one of my file, the xslt process takes 70 seconds and the bulk load with translated xml only takes 50 seconds. It would be great if we could save that 70 seconds in xslt.
|||Can you move to MSXML4? The performance of XSLT there was greatly improved.
Irwin Dolobowsky
Program Manager - SqlXml
http://weblogs.asp.net/irwando
This posting is provided "AS IS" with no warranties, and confers no rights.
"Evangeline" <anonymous@.discussions.microsoft.com> wrote in message
news:BAAC30DF-5073-48EC-9318-AFF09406224A@.microsoft.com...
> Thank you very much for your help.
> I was trying to avoid using xslt because it adds too much overhead to the
process.
> for example, I'm using MSXML3 object to transform one of my file, the xslt
process takes 70 seconds and the bulk load with translated xml only takes 50
seconds. It would be great if we could save that 70 seconds in xslt.
|||Thanks a lot. MSXML4 does cut the XSLT translation time to 40% less than MSXML3.
Just being curious, is there any other XML/XSLT component that has better performance than MSXML4? maybe some Java component?

No comments:

Post a Comment