开发者

Simple question about xml element in C#

开发者 https://www.devze.com 2023-03-17 03:01 出处:网络
I\'m not good in ASP.NET(c#) and XML. I have a textbox control, a button, and a website url(ex: http://chelseacole.com/question) has content of a xml file, like this:

I'm not good in ASP.NET(c#) and XML. I have a textbox control, a button, and a website url(ex: http://chelseacole.com/question) has content of a xml file, like this:

<paragraph>
<text att1="1" att2="2">
        facebook, facebook, facebook, facebook.
</text>
<text att1="3" a开发者_Python百科tt2="4">
        twitter, twitter, twitter, twitter.
</text>
<text att1="5" att2="6">
        facebook, twitter, facebook, twitter.
</text>
</paragraph>

So what I want is: went I click the button, the result will appear in the textbox control, like this:

facebook, facebook, facebook, facebook.
twitter, twitter, twitter, twitter.
facebook, twitter, facebook, twitter.

Anyone gonna help me? Thanks in advance! :">


If I've understand what do you want to achieve, try something like this:

XDocument document = XDocument.Load("file.xml");

or:

XDocument document = XDocument.Parse("<paragraph><text att ... ");

foreach (XElement item in document.Descendants("text"))
    textbox.Text+=item.Value + Environment.NewLine;


You could check this

LINQ to read XML

I would not recommend any other solution than this

0

精彩评论

暂无评论...
验证码 换一张
取 消