コンポーネントソースから入力を受け取り、簡単にトラバースできるXmlElement
ように変換するC# TBB を作成しています。XPathDocument
次に、取得したコンテンツを を使用してメモリ ストリームに書き込みますXmlWriter
。最後に、それを output にプッシュしていますXmlDocument
。出力 xml ドキュメントでは、 < > などの文字が のようなエンコード形式で表示されます<
>
。これらの文字のエンコードを防ぐにはどうすればよいですか?
<%@Import NameSpace="System.IO"%>
<%@Import Namespace="System.Xml.XPath"%>
<%@Import nameSpace="Tridion.ContentManager.CommunicationManagement"%>
using (MemoryStream ms = new MemoryStream())
{
TemplatingLogger log = TemplatingLogger.GetLogger(typeof(test));
XmlTextWriter securboxXmlWriter = new XmlTextWriter(ms, new System.Text.UTF8Encoding(true));
securboxXmlWriter.Indentation = 4;
securboxXmlWriter.Formatting = Formatting.Indented;
securboxXmlWriter.WriteStartDocument();
securboxXmlWriter.WriteStartElement("comp");
securboxXmlWriter.WriteAttributeString("xmlns", "http://www.w3.org/1999/xhtml");
securboxXmlWriter.WriteStartElement("con");
securboxXmlWriter.WriteStartElement("wf:wf");
securboxXmlWriter.WriteStartElement("wf:sI");
Component component=null;
string componentId = string.Empty;
try
{
component = engine.GetObject(package.GetByName(Package.ComponentName)) as Component;
log.Debug("componentId:"+component.Id);
}
catch (Exception e)
{
throw new InvalidOperationException("Component not found:" + e);
}
XmlElement componentxml = component.Content; // - this will give the xml Source of the component.
XmlDocument compXMLDoc = new XmlDocument();//- Creating the xml document
StringBuilder xmlTextBuilder = new StringBuilder();
XmlWriter xmlWriter = new XmlTextWriter(new StringWriter(xmlTextBuilder));
componentxml.WriteTo(xmlWriter);
compXMLDoc.Load(new StringReader(xmlTextBuilder.ToString()));
MemoryStream memStream = new MemoryStream();
compXMLDoc.Save(memStream);
memStream.Position = 0;
XPathDocument xpathDoc = new XPathDocument(memStream);//creating xpath document
String groupBodyComponent = String.Empty;
String gBCValue = String.Empty;
XPathNavigator nav = xpathDoc.CreateNavigator();
String value = string.Empty;
test t = new test();
// move to first element
nav.MoveToFirstChild();
nav.MoveToFirstChild();
//begin looping through the nodes
do
{
if (nav.Name.Equals("aH"))
{
securboxXmlWriter.WriteStartElement("wg:" + nav.Name);
if (nav.MoveToFirstChild())
{
gBC = nav.InnerXml;
switch(gBC){
case "bPTt":
while (nav.MoveToNext())
{
log.Debug(nav.Name);
if (nav.Name.Equals("value"))
{
gBCValue = nav.InnerXml;
}
securboxXmlWriter.WriteStartElement("wg:" + gBC);
value = t.replaceDynamicVariable(gBCValue);//will have some html tags in it
securboxXmlWriter.WriteElementString("text", value);
securboxXmlWriter.WriteEndElement();
}
break;
}
}
value = t.replaceDynamicVariable(nav.InnerXml);
securboxXmlWriter.WriteElementString("text", value);
securboxXmlWriter.WriteEndElement();
}
} while (nav.MoveToNext());
securboxXmlWriter.WriteEndElement();
securboxXmlWriter.WriteEndElement();
securboxXmlWriter.WriteEndElement();
securboxXmlWriter.WriteEndElement();
securboxXmlWriter.WriteEndDocument();
securboxXmlWriter.Flush();
securboxXmlWriter.Close();
Item output = package.GetByName("Output");
if (output != null)
{
package.Remove(output);
}
package.PushItem("Output", package.CreateStringItem(ContentType.Xml, Encoding.UTF8.GetString(ms.ToArray())));
}
コード スニペットを確認し、問題を解決する方法を提案してください。