开发者

Parse xml and apply formating to text

I am storing some text in a XML file and want to display it in my application by applying the formating to the text in a RichTextBox or something similar (maybe it would be better to have it as a listbox too?)

it would be something like this

<Text> 
  <Normal> This is some <Bold> text </Bold> which i like to put somewhere </Normal>
  <Bold><Italic> But there is a problem </Italic></Bold>
  <Normal> I don't know how </Normal>
</Text>

this text would look like this

This is some text which i like to put somewhere But there is a problem I don开发者_开发技巧't know how

I have searched the net but didnt find any solution...

Edit: I forgot to say that I am developing a silverlight navigation application so i cant user flowdocuments:/


You'd have to manually go through the XML nodes and define what should happen for each node. There's many different ways to implement something like that, but I'd start by keeping it simple.

For example: (pseudocode)

Foreach XMLnode node in xmlnodes
{
    if (node.attribute == "bold")
    {
        // apply bold to node text
    }
}

You can do it like this, which is fairly simple. I'm sure there is many ways to improve upon it and it can get fairly complicated I'm sure.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜