<?xml version="1.0" encoding="UTF-8" ?>
<customers>
<customer code="ARUNI" name="PUMA ARGENTINA/UNISOL" region="Latin America" country="Argentina" />
<customer code="AUPUA" name="Puma Australia Pty Ltd" region="APAC, Ex Japan" country="Australia" />
</customers> 請問大家:
型如上面XML文件如何區裡面字段數據(customer code,name,region,country)
多謝.
<customers>
<customer code="ARUNI" name="PUMA ARGENTINA/UNISOL" region="Latin America" country="Argentina" />
<customer code="AUPUA" name="Puma Australia Pty Ltd" region="APAC, Ex Japan" country="Australia" />
</customers> 請問大家:
型如上面XML文件如何區裡面字段數據(customer code,name,region,country)
多謝.
DECLARE @idoc int
DECLARE @doc varchar(1000)
SET @doc ='
<?xml version="1.0" encoding="UTF-8" ?>
<customers>
<customer code="ARUNI" name="PUMA ARGENTINA/UNISOL" region="Latin America" country="Argentina" />
<customer code="AUPUA" name="Puma Australia Pty Ltd" region="APAC, Ex Japan" country="Australia" />
</customers>'
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
-- Execute a SELECT statement that uses the OPENXML rowset provider.
SELECT *
FROM OPENXML (@idoc, '/customers/customer',2)
WITH (code varchar(10) '@code',
name varchar(20) '@name',
region varchar(20) '@region',
country varchar(20) '@country')
/*
code name region country
---------- -------------------- -------------------- --------------------
ARUNI PUMA ARGENTINA/UNISO Latin America Argentina
AUPUA Puma Australia Pty L APAC, Ex Japan Australia(所影响的行数为 2 行)*/
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("db.xml"));
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("a.xml"));
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
Response.Write(ds.Tables[0].Rows[i][j]); } }
接分了.