0

Let's assume that we have an XML File.

<world>
    <country > 
        <name>INDIA</name>
        <states>#states_count</states> // the place where i need to need to insert.
    </country>
    <country > 
        <name>SRILANKA</name>
        <states>9 states</states>
    </country>
</world>

I have a string in C# which contains

String states_count  = "29 states";

i replaced this by parsing ,travering to the node using XmlDocument and pasting the string to innerxml.

This is not what i need , i need to find "#states_count" token in xml, and replace the "states_count" string using preprocessor technique.

is it possible using preprocessor technique ?

if yes , please help me in this.

Thank you.

mnieto
  • 3,744
  • 4
  • 21
  • 37
Sivabalakrishnan
  • 475
  • 1
  • 7
  • 23
  • 1
    Hmm, no, that's a pretty meaningless approach. Load the xml file, change the data, save it back. It doesn't get simpler than that. – Hans Passant Oct 10 '18 at 11:38
  • Or use XSLT then there is no C# coding involved. Like this: https://stackoverflow.com/questions/10430411/update-the-text-of-an-element-with-xslt-based-on-param – Neil Oct 10 '18 at 11:50

1 Answers1

1

Read your XML file in as a string, do a string replace, load the string as XML with xmlDoc.LoadXml() instead of reading the file.

AndrewWhalan
  • 417
  • 3
  • 12