I am creating C # TBB. I have an XML code as shown below.
<content>
<ah>123</ah>
<ph>456</ph>
<body>
<sc>hi</sc>
<value>aa</value>
<value>bb</value>
<value>cc</value>
<value>dd</value>
<value>dd</value>
</body>
<body>
<sc>hello</sc>
<value>ee</value>
<value>ddff</value>
</body>
</content>
C # TBB Code:
using (MemoryStream ms = new MemoryStream())
{
XmlTextWriter securboxXmlWriter = new XmlTextWriter(ms, new System.Text.UTF8Encoding(false));
securboxXmlWriter.Indentation = 4;
securboxXmlWriter.Formatting = Formatting.Indented;
securboxXmlWriter.WriteStartDocument();
securboxXmlWriter.WriteStartElement("component");
securboxXmlWriter.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
securboxXmlWriter.WriteAttributeString("xmlns", "http://www.w3.org/1999/xhtml");
securboxXmlWriter.WriteStartElement("content");
securboxXmlWriter.WriteStartElement("wire:wire");
securboxXmlWriter.WriteStartElement("wire:si");
securboxXmlWriter.WriteStartElement("wg:ah");
securboxXmlWriter.WriteElementString("text", package.GetValue("Component.ah"));
securboxXmlWriter.WriteEndElement();
securboxXmlWriter.WriteStartElement("wg:ph");
securboxXmlWriter.WriteElementString("nlt", package.GetValue("Component.ph"));
securboxXmlWriter.WriteEndElement();
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())));
}
In the body tag, XML code occurs several times. I need to extract the contents of each tag. For this I use the HTML flexibility package. To make it work in C # TBB, how do I add a dll for HTML magic to the Tridion system? Also, please give a sample code snippet in html agility to skip body tags.
If HTML Agility won't work with C # TBB, please offer me a way to get the contents of the body tag.
Thanks in advance. Higher answer is welcome.
source
share