I have an XmlDocument object in memory, here's a sample of data:
& Lt; Conditions & gt; & Lt; The name of the letter = "F" & gt; & Lt; Period & gt; & Lt; Name & gt; FascĂculo & lt; / Name & gt; & Lt; Translate language = "n" & gt; Fascal & lt; / Translation & gt; & Lt; Definition & gt; Chicino Pasquetti de Fibras nerviosus o muscles & lt; / Definition & gt; & Lt; / Period & gt;
(there are many words in the original document)
I want to find a word from my name node, and then add an element as a child The term
& lt; Terms & gt; & Lt; The name of the letter = "F" & gt; & Lt; Period & gt; & Lt; Name & gt; FascĂculo & lt; / Name & gt; & Lt; Translate language = "n" & gt; Fascal & lt; / Translation & gt; & Lt; Definition & gt; Chicino Pasquetti de Fibras nerviosus o muscles & lt; / Definition & gt; & Lt; Image & gt; Hi there & lt; / Image & gt; & Lt; / Period & gt;
Now I can get it Xpath, find the node, then create a new node with new values, blah blah
But it all looks a bit long-winded in the world of Lankan.
This is what I have done so far:
Private static XmlDocument AddImages (XmlDocument TermDoc) {XDocument xDoc = XDocument.Load (New XmlNodeReader (termDoc)); (CSVRder CSV = New CSVRder (New Stream Reader ("SP2 Gaga's CSV"), Incorrect)) (CSV. Reed-NXTered (); csv.ReadNextRecord (); XElement SelectedTerm; string name, ImageRep; while (csv. ReadNextRecord ()) {imageref = csv [0] .restring (); name = csv [3] .restring (); selectterm = xDoc.Descendants ("word"). Single (t = & gt; T. desendents (" Name "). Single () value == name); // now want to add a new node and save it back to worddoc in any way}} return word Doc;}
But I'm lost from there. Any thoughts?
The following will add the element to you
Single (t = & gt; t desendants ("name"). Single (). Value == name). Add (new excelment ( "Image", "Hi there"));
The biggest issue I'm seeing that is making this clunky is the fact that switching back between XmlDocument and XDocument I would recommend that if you are going to use XmlDocument Not use XPath and if you want to use LINQ to use XDocument it will kill the constant switching performance and maintenance.