0

I have a xml file:

<xml ?iwes sf>
    <product>
        <name> Computer </name>
        <details>a product of Dell</details>
        <sender> sender no name</sender>
    </product>
</xml>

i want split to:

<xml ?iwes sf>,     ,<product>,         ,<name>,Computer,</name>,...,    ,</xml>

Then i translate text content (Computer,a product of Dell, sender no name) to Korean Language. Finally, i want join

<xml ?iwes sf>,     ,<product>,         ,<name>,Computer,</name>,...,    ,</xml>

with result translated:

<xml ?iwes sf>
    <product>
        <name> 컴퓨터</name>
        <details>Dell의 제품 </details>
        <sender> 아니오 유명한 송신기 </sender>
    </product>
</xml>

i used Regex:

string[] gettag = Regex.Split(inputText.Text, "(<.*?>)|(.+?(?=<|$))");

but it's wrong, it cann't do what i want, i cann't join xml tag to location before, cause it cann't get "\t"! What should i do?? My English level is'ot good. I hope everyone can understand what i said and help me! Thanks!

hazymnc
  • 107
  • 1
  • 10
  • 2
    Did you consider a proper XML parser before regex? – Jerry Jan 08 '14 at 10:40
  • 1
    Don't use RegEx for that. Use Linq or XPath. – germi Jan 08 '14 at 10:44
  • I just split all of the file. If i split file by line i can check it. – hazymnc Jan 08 '14 at 10:45
  • 2
    Seem some reasons why parsing XML/HTML with regex is hard/impractical [on this link](http://stackoverflow.com/questions/701166/can-you-provide-some-examples-of-why-it-is-hard-to-parse-xml-and-html-with-a-reg). As germi has mention, check out [linq to xml](http://www.dreamincode.net/forums/topic/218979-linq-to-xml/) or [XPath](http://msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx) – Amicable Jan 08 '14 at 10:47
  • @germi: Can you instructions for me? – hazymnc Jan 08 '14 at 10:48
  • 2
    @user3172506: Amicable posted a link to a tutorial. Check that out. If that still doesn't help, come back with your exact problem. – germi Jan 08 '14 at 10:58

1 Answers1

0

y not some lambda expression ?

you can try this.

      IEnumerable<XElement> xx = xdoc.Root.Descendants().Elements().Where(c => { if (c.Name == "name") { c.Value = "Dell"; } else if (c.Name == "details") { c.Value = "Dell Detial"; } return true; }).Select(c => c);


            // Loop.
            string x = string.Empty;
            foreach (XElement x1 in xx)
            {
                x += x1.ToString();
            }

      Console.WriteLine(x.ToString());
shujaat siddiqui
  • 1,527
  • 1
  • 20
  • 41