如何在c#中使用XML [英] HOW TO PARSE XML IN c#
本文介绍了如何在c#中使用XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
-<SalesOrders>
- <SalesOrder>
<OrderNo>1001</OrderNo>
<InvoiceNo>10001</InvoiceNo>
<CustomerID>b46aa871-b9d4-4ee4-8881-78bb5307b35d</CustomerID>
<Customer>Numeri Consulting AS</Customer>
<Created>2011-12-21T11:17:41+01:00</Created>
<Modified>2011-12-21T11:22:47+01:00</Modified>
- <SalesOrderDetails>
<LineNo>10</LineNo>
<ProductID>c1f128ca-0db8-4d79-ac83-0650e558230d</ProductID>
<Product>100 - Iphone4</Product>
<Tax>1000.0000</Tax>
<Amount>4000.0000</Amount>
</SalesOrderDetails>
- <SalesOrderDetails>
<LineNo>20</LineNo>
<ProductID>2f08b82f-828d-4792-a70d-f2ba9fba9f7e</ProductID>
<Product>1000 - Hodetelefoner</Product>
<Tax>75.0000</Tax>
<Amount>300.0000</Amount>
</SalesOrderDetails>
</SalesOrder>
-</SalesOrders>
我已经为每个销售订单提供XML,我有一个产品和多个产品如何获得客户和产品ID并进行操作
例如ID = b46aa871-b9d4-4ee4-8881-78bb5307b35d和
产品编号[ 0] = c1f128ca-0db8-4d79-ac83-0650e558230d
产品编号[1] = 2f08b82f-828d-4792-a70d-f2ba9fba9f7e
一位客户在这里有两个产品因此我想插入数据库
I HAVE ABOVE XML FOR EACH SALES ORDER I HAVE ONE CUST AND MULTIPLE PRODUCTS HOW TO GET CUSTOMER AND PRODUCT ID AND DO THE OPERATIONN
FOR EXAMPLE CUST ID =b46aa871-b9d4-4ee4-8881-78bb5307b35d AND
PRODUCT ID[0] = c1f128ca-0db8-4d79-ac83-0650e558230d
PRODUCT ID [1] = 2f08b82f-828d-4792-a70d-f2ba9fba9f7e
FOR ONE CUSTOMER HERE THERE IS TWO PRODUCT SO I WOULD LIKE TO INSERT IN DB
推荐答案
有不同的方法完全实现特技在.NET FCL。请参阅我的简短概述:
There are different approaches fully implemented in .NET FCL. Please see my short overview of them:
- 使用
System.Xml.XmlDocument
class 。它实现了DOM接口;如果文档的大小不是太大,这种方式是最简单和最好的。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ]。 - 使用类
System.Xml.XmlTextReader
;这是最快的阅读方式,特别是你需要跳过一些数据。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ ^ ]。 - 使用类
System.Xml.Linq.XDocument
;这是类似于XmlDocument
的最合适的方式,支持LINQ to XML Programming。
参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ],http://msdn.microsoft.com/en-us/library/bb387063.aspx [ ^ ]。
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the class
System.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that ofXmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
您好,
看看这里:
在C#中使用XmlReader类 [ ^ ]
LINQ to XML [ ^ ]
http://www.c-sharpcorner.com/UploadFile/mahesh/ReadWriteXMLTutMellli2111282005041517AM/ReadWriteXMLTutMellli21。 aspx [ ^ ]
http:// forum。 codecall.net/topic/58239-c-tutorial-reading-and-writing-xml-files/ [ ^ ]
http://www.dotnetperls.com/xmlreader [ ^ ]
http://www.dreamincode.net / forums / topic / 218979-linq-to-xml / [ ^ ]
Hi,
Have a look here:
Using the XmlReader class with C#[^]
LINQ to XML[^]
http://www.c-sharpcorner.com/UploadFile/mahesh/ReadWriteXMLTutMellli2111282005041517AM/ReadWriteXMLTutMellli21.aspx[^]
http://forum.codecall.net/topic/58239-c-tutorial-reading-and-writing-xml-files/[^]
http://www.dotnetperls.com/xmlreader[^]
http://www.dreamincode.net/forums/topic/218979-linq-to-xml/[^]
http://msdn.microsoft.com/en-us/library/cc189056(v = vs.95)。 aspx
浏览以上链接
http://msdn.microsoft.com/en-us/library/cc189056(v=vs.95).aspx
Go through the above link
这篇关于如何在c#中使用XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文