am trying to convert the XML to Json Conversion by applying the xslt transformation using following code in C#. Am getting following error can any one suggest me on below? Code:
Li = p.GetRegisterEntry();
var std = Li.Where(s => s.Id == id).FirstOrDefault();
string xml = std.contentxml.Value;
doc.LoadXml(xml);
string XSLT = std.TemplateXSLT.Value;
Xslt.LoadXml(XSLT);
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(Xslt.CreateNavigator());
// Transform our Xml-ified JSON
var outputDocument = new XmlDocument();
var stream = new MemoryStream();
xslt.Transform(doc, null, stream);
var sr = new StreamReader(stream);
var myStr = sr.ReadToEnd();
stream.Position = 0;
outputDocument.Load(stream);
// Convert back to JSON
string jsonText = JsonConvert.SerializeXmlNode(outputDocument);
am getting the following error at outputDocument.Load(stream); An exception of type 'System.Xml.XmlException' occurred in System.Xml.dll but was not handled in user code Additional information: There are multiple root elements. Line 2, position 2.
can any one please help me to crack this?
here are my XML and XSTL Files XML:
<NewDataSet>
<RegisterEntry type="CM2" desc="Request to Change Name, Address and /or Singapore Address for Service for Agent, Applicant/Proprietor and/or other interested Parties">
<EventDate>23/09/2051</EventDate>
<DataItems>
<LodgementDate>26/08/2022</LodgementDate>
<DecisionDate>21/12/2031</DecisionDate>
<Particulars>
<Particular>
<TransactionType>Test Data</TransactionType>
<Details>Test Data</Details>
</Particular>
</Particulars>
</DataItems>
</RegisterEntry>
</NewDataSet>
XSLT :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:template match="RegisterEntry">
<p> Test Data Parties<xsl:value-of select="DataItems/TransactionType" /></p>
<div id="content">
<table>
<tr>
<th valign="top" align="left"> Lodgement Date </th>
<td>
<xsl:value-of select="DataItems/LodgementDate" />
</td>
</tr>
<tr>
<th valign="top" align="left"> Decision Date </th>
<td>
<xsl:value-of select="DataItems/DecisionDate" />
</td>
</tr>
<xsl:for-each select="DataItems/Particulars/Particular">
<tr>
<th valign="top" align="left" style="width:50%"> Test Data <xsl:value-of select="TransactionType" /></th>
<td>
<xsl:value-of select="Details" />
</td>
</tr>
</xsl:for-each>
</table>
</div>
</xsl:template>
</xsl:stylesheet>