插入文本节点包含XML XML文档 [英] Insert text node to XML document containing XML
问题描述
我建立一个XML文档动态,我创建一个createTextNode AA文本节点(文本)方法。
现在的情况下, 文字包含XML它将XML编码
例如:
文本=一些< b>粗体< / b>文字
< 。p>你怎么插入而不XML编码的文本
编辑:
我建立一个同的XmlDocument和插入元件和节点的XML文档。
最终的输出不应该包含CDATA节或编码的部分。
有关instace我想最终的输出看起来是这样,这里的文字来自设定
<根>< p>有的< b>粗体< / b>文字< / P>< /根>
如果你想在文本为有些< b>粗体< / b>文字
,那么编码是在右侧的事情 - 否则就不是(刚)文本节点。你可以CDATA它,但我不认为这是你的意思是不是。
你想XML内容是上面?也就是说,使其得到了< B> ...< / B>
elelment 里面
编辑:这里的,增加了通过各种方法内容的代码:
字符串的txt =一些< b>粗体< / b>文字;
XmlDocument的DOC =新的XmlDocument();
doc.LoadXml(< XML><富/>< / XML>);
的XmlElement富=(的XmlElement)doc.SelectSingleNode(//富);
//文本:LT;富>有的和放大器; LT; B和; GT;&加粗放大器; LT; / B&放大器; GT;文字< / foo的>
foo.RemoveAll();
foo.InnerText = TXT;
Console.WriteLine(foo.OuterXml);
// XML:LT;富>有的< B>粗体< / B>文字< / foo的>
foo.RemoveAll();
foo.InnerXml = TXT;
Console.WriteLine(foo.OuterXml);
// CDATA:<富>< [CDATA [一些< B>粗体< / B>文本]>< / foo的>
foo.RemoveAll();
foo.AppendChild(doc.CreateCDataSection(TXT));
Console.WriteLine(foo.OuterXml);
I'm building a XML document dynamically where I create a a text node with CreateTextNode(text) method.
Now in case the text contains XML it will be XML encoded.
For instance:
text = "some <b>bolded</b> text"
How do you insert the text without being XML encoded.
EDIT:
I'm building a XML document with XmlDocument and insert elements and nodes. The final output should not contain CDATA sections or encoded parts.
For instace I want the final output to look like this, where the text comes from a setting:
<root><p>Some <b>bolded</b> text</p></root>
If you want the text to be "some <b>bolded</b> text"
, then encoding is the right thing - otherwise it isn't (just) a text node. You could CDATA it, but I don't think that is what you mean either.
Do you want the xml contents to be the above? i.e. so that it gets a <b>...</b>
elelment inside it?
edit: here's code that adds the content via various methods:
string txt = "some <b>bolded</b> text";
XmlDocument doc = new XmlDocument();
doc.LoadXml("<xml><foo/></xml>");
XmlElement foo = (XmlElement)doc.SelectSingleNode("//foo");
// text: <foo>some <b>bolded</b> text</foo>
foo.RemoveAll();
foo.InnerText = txt;
Console.WriteLine(foo.OuterXml);
// xml: <foo>some <b>bolded</b> text</foo>
foo.RemoveAll();
foo.InnerXml = txt;
Console.WriteLine(foo.OuterXml);
// CDATA: <foo><![CDATA[some <b>bolded</b> text]]></foo>
foo.RemoveAll();
foo.AppendChild(doc.CreateCDataSection(txt));
Console.WriteLine(foo.OuterXml);
这篇关于插入文本节点包含XML XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!