내부에 여러 요소가있는 XML 문서를 만들고 싶습니다. 형식은 다음과 같이해야한다 :여러 xml 요소를 C로 삽입하십시오 #
<Item>
<Id>2276138</Id>
<Title>92907-03100-00 WASHER, CHAIN</Title>
<Link>http://www.mywebsite.com/Product.aspx?ProductId=2453575&SKU=92907-03100-00</Link>
<Price>0.0000</Price>
<Description>WASHER, CHAIN (92907-03100-00)</Description>
<Condition>New</Condition>
<Brand />
<Product_Type />
<Availability>In Stock</Availability>
<Manufacturer>Suzuki</Manufacturer>
</Item>
모든 데이터를 가져 오는 첫 번째 루프 후 확인하지만, 2 차 루프가 완료되면,이 있습니다 : 그래서 모든 라운드 후
<Item></Item>
<Item>
<Id>2276138</Id>
<Title>92907-03100-00 WASHER, CHAIN</Title>
<Link>http://www.mywebsite.com/Product.aspx?ProductId=2453575&SKU=92907-03100-00</Link>
<Price>0.0000</Price>
<Description>WASHER, CHAIN (92907-03100-00)</Description>
<Condition>New</Condition>
<Brand />
<Product_Type />
<Availability>In Stock</Availability>
<Manufacturer>Suzuki</Manufacturer>
</Item>
을 인출하면 빈 항목 요소가 생기고 마지막 요소 만 채워집니다. 데이터가 올바르게 가져올 수 있도록,
while (rdr.Read())
{
if (rdr.HasRows)
{
XmlElement part = docOrders.CreateElement("Item");
id.InnerText = rdr[0].ToString();
part.AppendChild(id);
title.InnerText = rdr[1].ToString();
part.AppendChild(title);
link.InnerText = rdr[2].ToString();
part.AppendChild(link);
price.InnerText = rdr[3].ToString();
part.AppendChild(price);
desc.InnerText = rdr[4].ToString();
part.AppendChild(desc);
cond.InnerText = rdr[5].ToString();
part.AppendChild(cond);
brand.InnerText = rdr[6].ToString();
part.AppendChild(brand);
productType.InnerText = rdr[7].ToString();
part.AppendChild(productType);
availability.InnerText = rdr[8].ToString();
part.AppendChild(availability);
manufacturer.InnerText = rdr[9].ToString();
part.AppendChild(manufacturer);
root.AppendChild(part);
}
}
rdr.Close();
}
가 어떻게이 문제를 해결할 수 있습니다 : 여기 는 루프에 대한 코드? 미리 감사드립니다.
참고로,하지만 당신은 rdr.HasRows 필요하지 않습니다. – Zachary