asp.net c# xml parser hjälp....
Visa första olästa |
| #1 | |
|
Mycket flitig postare
| Hej,
jag har ett xml som jag skulle vilja parsa ut... någon som man hjälpa mig... CODE <database><DELTACO.SE><version>1.0</version><data information="Items Stock Price"><items><item id="03-TP"><stock quantity="942"/><price><net price="15,22"/></price></item><item id="05-6420"><stock quantity="158"/><price><net price="15,22"/></price></item><item id="05-6421"><stock quantity="46"/><price><net price="15,22"/></price></item><item id="ZIF-IDE40-A"><statuses><status id="1">Utgått.</status></statuses></item></items></data></DELTACO.SE></database> det jag skulle vilja få ut efter varje loop är : id, quantity och price |
| #2 | |
|
Klarade millennium-buggen
|
Det är inte alls svårt att hitta hur man gör:
t ex http://www.doublecloud.org/2013/08/parsing-xml-in-c-a-quick-working-sample/ |
| #3 | |
|
Mycket flitig postare
|
har kommit så långt, men får inte tag på price.... :S
CODE
string sStock;
string sPrice;
XmlDocument doc = new XmlDocument();
doc.Load(MapPath("../XML/stockandprice.xml"));
XmlNodeList nodes = doc.DocumentElement.SelectNodes("/database/DELTACO.SE/data/items/item");
foreach (XmlNode node in nodes)
{
string sProductID = node.Attributes["id"].Value;
//book.author = node.SelectSingleNode("author").InnerText;
foreach (XmlNode subNode in node)
{
if (subNode.Name == "stock")
{
sStock = subNode.Attributes["quantity"].Value;
}
else
{
XmlNodeList nodes2 = doc.DocumentElement.SelectNodes("/database/DELTACO.SE/data/items/item/price");
foreach (XmlNode subNode2 in nodes2)
{
sPrice = subNode2.Attributes["price"].Value;
}
}
}
}
|
| #4 | |
|
Klarade millennium-buggen
|
debugga och se vad nodarna heter ?!
|
| #5 | |
|
Mycket flitig postare
|
subNode2 är flera noder och inte bara en.
|
Aktiva användare som för närvarande tittar på det här ämnet: 0 (0 medlemmar och 0 gäster)

Visa första olästa