Click here to Skip to main content
15,890,717 members
Home / Discussions / C#
   

C#

 
GeneralRe: Regarding Globalization Pin
vijaylumar13-Oct-09 1:41
vijaylumar13-Oct-09 1:41 
GeneralRe: Regarding Globalization Pin
stancrm13-Oct-09 1:46
stancrm13-Oct-09 1:46 
GeneralRe: Regarding Globalization Pin
vijaylumar13-Oct-09 1:59
vijaylumar13-Oct-09 1:59 
GeneralRe: Regarding Globalization Pin
stancrm13-Oct-09 2:04
stancrm13-Oct-09 2:04 
GeneralRe: Regarding Globalization Pin
benjymous13-Oct-09 3:04
benjymous13-Oct-09 3:04 
GeneralRe: Regarding Globalization Pin
Eddy Vluggen13-Oct-09 3:10
professionalEddy Vluggen13-Oct-09 3:10 
QuestionSimulation mobile users in network Pin
trungtin13-Oct-09 0:10
trungtin13-Oct-09 0:10 
QuestionxmlDocument Pin
arkiboys12-Oct-09 23:40
arkiboys12-Oct-09 23:40 
Hi,
Assuming I have an xml file which looks something like:

<main>
<field1>
<table>
<columns>
<column>
<ElementName>1234</ElementName>
<ElementValue>uyt</ElementValue>
</column>
...
</columns>
</table>
</field1>
...
<field2>

<table>
<columns>
<column>
<ElementName>654322</ElementName>
<ElementValue>xyz</ElementValue>
</column>
...
</columns>
</table>
...
</field2>
...
...
</main>

The code below retrieves the values for
ElementName>654322</ElementName> and
<ElementValue>xyz</ElementValue> as shown:

private void ModifyXML()
{
XmlDocument doc = new XmlDocument();
doc.Load(strPath);

// Retrieve all prices.
XmlNodeList nodeList = doc.GetElementsByTagName("ElementName");

foreach (XmlNode node in nodeList)
{
string strValue = node.ChildNodes[0].Value.ToString();
if (strValue.ToLower() == "654322")
{
ListBox1.Items.Add(node.OuterXml);
ListBox1.Items.Add(node.NextSibling.OuterXml);
ListBox1.Items.Add("");

//Console.WriteLine(node.ChildNodes[0].Value);
//Console.WriteLine(node.NextSibling.InnerXml);
}
}
}


Question:

Please note that I do not want to use xpath or linq or database. Just the xmlDocument for business reasons

Using this code below, how can I add a column element i.e.

Thanks

<column>
<ElementName>newValue</ElementName>
<ElementValue>newdata</ElementValue>
</column>

OR

delete one of the above column elements i.e. to remove:
<column>
<ElementName>654322</ElementName>
<ElementValue>xyz</ElementValue>
</column>
AnswerRe: xmlDocument Pin
SeMartens12-Oct-09 23:55
SeMartens12-Oct-09 23:55 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 0:43
arkiboys13-Oct-09 0:43 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 0:46
SeMartens13-Oct-09 0:46 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 0:51
arkiboys13-Oct-09 0:51 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 1:02
SeMartens13-Oct-09 1:02 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 1:19
arkiboys13-Oct-09 1:19 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 1:25
SeMartens13-Oct-09 1:25 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 1:29
arkiboys13-Oct-09 1:29 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 1:32
SeMartens13-Oct-09 1:32 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 1:35
arkiboys13-Oct-09 1:35 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 1:38
SeMartens13-Oct-09 1:38 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 1:41
arkiboys13-Oct-09 1:41 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 1:47
SeMartens13-Oct-09 1:47 
GeneralRe: xmlDocument [modified] Pin
arkiboys13-Oct-09 1:59
arkiboys13-Oct-09 1:59 
GeneralRe: xmlDocument Pin
SeMartens13-Oct-09 2:09
SeMartens13-Oct-09 2:09 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 2:16
arkiboys13-Oct-09 2:16 
GeneralRe: xmlDocument Pin
arkiboys13-Oct-09 4:23
arkiboys13-Oct-09 4:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.