如何将XML读入SQL? -我应该使用LINQ吗 [英] How to read XML into SQL? - Should I use LINQ

查看:72
本文介绍了如何将XML读入SQL? -我应该使用LINQ吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我(示例代码)如何将此XML读取到SQL DB中吗?我应该使用LINQ to XML吗?有人有示例代码吗?
我正在使用VB.NET

<?xml version ="1.0" encoding ="utf-8"?>

< ReadOrderResponseType xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd ="http://www.w3.org/2001/XMLSchema">

< Status xmlns ="urn:mysol:apis">成功</Status>

< TimeStamp xmlns ="urn:mysol:apis"> 2010-07-25T15:26:49.1150235Z</TimeStamp>

< StoreUrl xmlns ="urn:mysol:apis"> http://xyz.COM</StoreUrl>

< PageResponse xmlns ="urn:mysol:apis">

< Page> 1</Page>

< Size> 10</Size>

< TotalSize> 18033</TotalSize>

< HasMore> true</HasMore>

</PageResponse>

< OrderList OrderId ="20147184" OrderNumber ="20100560" xmlns ="urn:mysol:apis">

<已归档> false</已归档>

< CreateDate> 2010-07-25T01:37:04.067Z</CreateDate>

< ReferringURL> http://www.ccc.com/Electronics/Landing1836a82496.html</ReferringURL>

< Customer>

<浏览器> Mozilla/4.0(兼容; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0;. NET4.0C)</Browser>

< Registered> false</Registered>

< IpAddress> 98.555.555.555</IpAddress>

< EmailAddress> xsd@yahoo.com</EmailAddress>

< NonTaxable> false</NonTaxable>

< BillingAddress>

<名字>约翰</名字>

< LastName> Doe</LastName>

< Address1>阿丹路222号(&/Address1>

< City> MyCity</City>

< StateProvince> PA</StateProvince>

< PostalCode> 15001</PostalCode>

< Country>美国</Country>

< Phone> 7245550000</Phone>

</BillingAddress>

< ShippingAddress>

<名字>约翰</名字>

< LastName> Doe</LastName>

< Address1>阿丹路222号(&/Address1>

< City> MyCity</City>

< StateProvince> PA</StateProvince>

< PostalCode> 15001</PostalCode>

< Country>美国</Country>

< Phone> 7245550000</Phone>

</ShippingAddress>

</客户>

<发票>

<小计货币="USD"> 11.99</小计>

< Shipping Currency ="USD"> 8.49</Shipping>

< Total Currency ="USD"> 20.48</Total>

< CombineHandling> true</CombineHandling>

< Weight UnitOfMeasure ="Imperial">

<主要> 3</主要>

<次要> 0.00</次要<

</重量>

< LineItemList LineItemId ="80927">

< FreeShipping> false</FreeShipping>

<名称> OEM标准电池</名称>

< NonTaxable> false</NonTaxable>

< PartNumber> AB463446FZ</PartNumber>

< ProductId> 82496</ProductId>

< ProductClass>常规</ProductClass>

< QtySold> 1</QtySold>

< Weight UnitOfMeasure ="Imperial">

<主要> 3</主要>

<次要> 0.00</次要<

</重量>

< UnitPrice货币="USD"> 11.99</UnitPrice>

< ShippingOption> Shippable</ShippingOption>

</LineItemList>

</发票>

<付款>

< AuthorizationId> 248459</AuthorizationId>

< TransactionId> 3100095455</TransactionId>

<信用卡>

<到期时间> 2012-05-01</到期时间>

<名字>约翰</名字>

< LastName> Doe</LastName>

< Number> 3333</Number>

< Issuer> AmericanExpress</Issuer>

<验证>

< Card>匹配</Card>

< PostalCode>匹配</PostalCode>

< Street>匹配</Street>

</验证>

</CreditCard>

< PaymentMethod> AuthorizeNet</PaymentMethod>

</付款>

<运费>

<名称>地面服务</名称>

<运营商>客户</运营商>

</运费>

<状态OrderStatusId ="1">

<名称>收到的订单</名称>

</状态>

< QuestionList>

< Title>复选框以直接下船</Title>

< Display> CheckBoxList</Display>

< BooleanAnswerList>

< Answer>订单将以帐单名称& amp;地址.便笺不包括在内.</答案>

< Value> false</Value>

</BooleanAnswerList>

</QuestionList>

< QuestionList>

< Title>销售人员初始</Title>

< Display> TextList</Display>

< TextAnswerList/>

</QuestionList>

</OrderList>

</ReadOrderResponseType>

解决方案

您可以使用LINQ或DOM.如果要从XML中提取数据,则可以在DOM中使用XPath或LINQ使用的任何东西来查找并提取数据,然后以通常的方式将其放入SQL db.

Can someone please tell me (sample code) how to read this XML into a SQL DB? Should I use LINQ to XML? Does anyone have any sample code?
I am using VB.NET

<?xml version="1.0" encoding="utf-8"?>

<ReadOrderResponseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<Status xmlns="urn:mysol:apis">Success</Status>

<TimeStamp xmlns="urn:mysol:apis">2010-07-25T15:26:49.1150235Z</TimeStamp>

<StoreUrl xmlns="urn:mysol:apis">http://xyz.COM</StoreUrl>

<PageResponse xmlns="urn:mysol:apis">

<Page>1</Page>

<Size>10</Size>

<TotalSize>18033</TotalSize>

<HasMore>true</HasMore>

</PageResponse>

<OrderList OrderId="20147184" OrderNumber="20100560" xmlns="urn:mysol:apis">

<Archived>false</Archived>

<CreateDate>2010-07-25T01:37:04.067Z</CreateDate>

<ReferringURL>http://www.ccc.com/Electronics/Landing1836a82496.html</ReferringURL>

<Customer>

<Browser>Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)</Browser>

<Registered>false</Registered>

<IpAddress>98.555.555.555</IpAddress>

<EmailAddress>xsd@yahoo.com</EmailAddress>

<NonTaxable>false</NonTaxable>

<BillingAddress>

<FirstName>John</FirstName>

<LastName>Doe</LastName>

<Address1>222 Adane Road</Address1>

<City>MyCity</City>

<StateProvince>PA</StateProvince>

<PostalCode>15001</PostalCode>

<Country>US</Country>

<Phone>7245550000</Phone>

</BillingAddress>

<ShippingAddress>

<FirstName>John</FirstName>

<LastName>Doe</LastName>

<Address1>222 Adane Road</Address1>

<City>MyCity</City>

<StateProvince>PA</StateProvince>

<PostalCode>15001</PostalCode>

<Country>US</Country>

<Phone>7245550000</Phone>

</ShippingAddress>

</Customer>

<Invoice>

<Subtotal Currency="USD">11.99</Subtotal>

<Shipping Currency="USD">8.49</Shipping>

<Total Currency="USD">20.48</Total>

<CombineHandling>true</CombineHandling>

<Weight UnitOfMeasure="Imperial">

<Major>3</Major>

<Minor>0.00</Minor>

</Weight>

<LineItemList LineItemId="80927">

<FreeShipping>false</FreeShipping>

<Name>OEM Standard battery</Name>

<NonTaxable>false</NonTaxable>

<PartNumber>AB463446FZ</PartNumber>

<ProductId>82496</ProductId>

<ProductClass>Regular</ProductClass>

<QtySold>1</QtySold>

<Weight UnitOfMeasure="Imperial">

<Major>3</Major>

<Minor>0.00</Minor>

</Weight>

<UnitPrice Currency="USD">11.99</UnitPrice>

<ShippingOption>Shippable</ShippingOption>

</LineItemList>

</Invoice>

<Payment>

<AuthorizationId>248459</AuthorizationId>

<TransactionId>3100095455</TransactionId>

<CreditCard>

<Expiration>2012-05-01</Expiration>

<FirstName>John</FirstName>

<LastName>Doe</LastName>

<Number>3333</Number>

<Issuer>AmericanExpress</Issuer>

<Verification>

<Card>Match</Card>

<PostalCode>Match</PostalCode>

<Street>Match</Street>

</Verification>

</CreditCard>

<PaymentMethod>AuthorizeNet</PaymentMethod>

</Payment>

<Shipping>

<Name>Ground Service</Name>

<Carrier>Customer</Carrier>

</Shipping>

<Status OrderStatusId="1">

<Name>Order Received</Name>

</Status>

<QuestionList>

<Title>Check box to blind drop-ship</Title>

<Display>CheckBoxList</Display>

<BooleanAnswerList>

<Answer>Order will be shipped as arriving from billing name &amp; address. Slip will not be included.</Answer>

<Value>false</Value>

</BooleanAnswerList>

</QuestionList>

<QuestionList>

<Title>sales person intial</Title>

<Display>TextList</Display>

<TextAnswerList />

</QuestionList>

</OrderList>

</ReadOrderResponseType>

解决方案

You can use LINQ, or use the DOM. If you want to extract the data from the XML, then you use XPath in the DOM, or whatever LINQ uses, to find the data and extract it, then put it in to your SQL db in the usual way from there.


这篇关于如何将XML读入SQL? -我应该使用LINQ吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆