Ajout noeud d'un doc dans un autre doc Xml
Bonjour,
Je viens de naviguer sur le web et j'ai trouvé des solutions à mon problème, mais elles ne semble pas fonctionner. Pourriez-vous jetez un coup d'oeil à ceci?
Fichier d'origine duquel je veux copier les noeuds sous promotions (I.e. promo)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <root>
<sites>
<site>blabla</site>
</sites>
<fichiers>
<fichier>aa.txt</fichier>
</fichiers>
<environnements>
<environnement>dev</environnement>
</environnements>
<promotions>
<promo nom="nom"/>
</promotions>
<autres>
<nombreMachineMoss>32</nombreMachineMoss>
</autres>
</root> |
Fichier destination dans lequel je copie les noeuds
Code:
1 2 3 4 5 6 7
| <root>
<promotions>
<promo nom = ""></promo>
</promotions>
</root> |
Ma fonction a l'air de ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| Public Sub AjouterSuppLignesDansPromotions(ByRef rXmlPromotions As XmlDocument, ByRef rConfig As XmlDocument)
Dim listeNoeudAAjouter As XmlNodeList
Dim listeNoeudPromotions As XmlNodeList
Dim noeudPromoParent As XmlNode = Nothing
Dim noeud, noeudPromo As XmlNode
listeNoeudAAjouter = rConfig.DocumentElement.GetElementsByTagName("promotions")
listeNoeudPromotions = rXmlPromotions.GetElementsByTagName("promotions")
For Each noeudPromoParent In listeNoeudPromotions
For Each noeudPromo In noeudPromoParent.ChildNodes
If noeudPromo.LocalName = "promo" Then
Exit For
End If
Next
Exit For
Next
noeudPromoParent = listeNoeudAAjouter(0)
For Each noeud In noeudPromoParent.ChildNodes
noeudPromoParent.AppendChild(rXmlPromotions.ImportNode(noeud, True))
Next
End Sub |
Merci!
Oubliez cela, j'ai fait moins compliqué!
Code:
1 2
| noeudPromoParent = listeNoeudAAjouter(0)
noeudPromo.ParentNode.InnerXml += noeudPromoParent.InnerXml |