2015-11-03 2 views
0

Я не буду добавлять строку в строку, у меня есть база данных xml для моего программного обеспечения, но я не понимаю, как добавить строку для этого стиля.vb.net добавить строку в строке xml

<facture> 
    <commande>000156</commande> 
    <date>Jan 1, 2003 14:30:00</date> 
    <commis>adsd</commis> 
    <client>0</client> 
    <item_liste> 
     <item_id>0</item_id> 
     <item_quantité>4</item_quantité> 
     <item_codebarre>0</item_codebarre> 
     <item_name>hejwkhe</item_name> 
     <item_price>55</item_price>     
     <item_tax>no</item_tax> 
    </item_liste> 
    <item_liste> 
     <item_id>2</item_id> 
     <item_quantité>5</item_quantité> 
     <item_codebarre>0</item_codebarre> 
     <item_name>ghskjfdghsfd</item_name> 
     <item_price>24</item_price>     
     <item_tax>yes</item_tax> 
    </item_liste> 
    <montant> 270 </montant> 
</facture> 

Я теперь добавить нормальный Row

dataTable1.Rows.Add(img12, "", "", "", "", "", "") 

Спасибо за помощь, и я прошу прощения за мой плохой английский.

+0

Показать результат, что вы ожидали – Fabio

+0

В результате то, что я показываю, но если у меня есть 5 пункт в мой счет у меня есть 5 в и is't только строки у меня есть , , , , и мой XML база

ответ

0

Вы можете использовать XML Linq

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Xml; 
using System.Xml.Linq; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      string xml = 
       "<facture>" + 
        "<commande>000156</commande>" + 
        "<date>Jan 1, 2003 14:30:00</date>" + 
        "<commis>adsd</commis>" + 
        "<client>0</client>" + 
        "<item_liste>" + 
         "<item_id>0</item_id>" + 
         "<item_quantité>4</item_quantité>" + 
         "<item_codebarre>0</item_codebarre>" + 
         "<item_name>hejwkhe</item_name>" + 
         "<item_price>55</item_price>" + 
         "<item_tax>no</item_tax>" + 
         "</item_liste>" + 
        "<item_liste>" + 
         "<item_id>2</item_id>" + 
         "<item_quantité>5</item_quantité>" + 
         "<item_codebarre>0</item_codebarre>" + 
         "<item_name>ghskjfdghsfd</item_name>" + 
         "<item_price>24</item_price>" + 
         "<item_tax>yes</item_tax>" + 
         "</item_liste>" + 
         "<montant> 270 </montant>" + 
        "</facture>"; 


      XElement facture = XElement.Parse(xml); 
      List<XElement> item_liste = facture.Descendants("item_liste").ToList(); 
      XElement newItem_liste = new XElement("item_liste", new XElement[] { 
       new XElement("item_id", 3), 
       new XElement("item_quantité", 5), 
       new XElement("item_codebarre", 0), 
       new XElement("item_name", "xyz"), 
       new XElement("item_price", 30), 
       new XElement("item_tax", "no") 
      }); 
      item_liste.Last().ReplaceWith(new object[] { item_liste.Last(), newItem_liste }); 
     } 
    } 
} 
​ 
0
Dim dr As DataRow 

' loop around the XML Nodes 
    For Each node As XmlNode In XML 

    ' declare a new row in your datatable 
dr = dataTable1.NewRow() 
'get what ever values you want off of the attribute of the node ie item name 
dr("item_name") = node.Attributes("item_name").Value 
dr("item_id") = node.Attributes("item_id").Value 

' add the row to your data table 
datatable1.rows.Add(dr) 
+0

Привет, Я не undertand, как добавить новое значение i f Я добавляю то же значение? Благодарю. –

Смежные вопросы