EDN Admin
Well-known member
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri Hi,
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri I got this excption when i tried to run the below piece of code in 4.0
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri "This document already has a DocumentElement node".
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal but the below same code works fine in 3.5. Here im pasting that code. Here im trying to call the DCLoad function for each and every xsl file of a directory.
<p style="margin:0in 0in 0pt; line-height:normal
<p style="margin:0in 0in 0pt; line-height:normal For the first call it is working fine, but when it is calling for the
second time it throws the above exception. Its going smooth in
3.5 but not in 4.0 , is there any specific reason for this?
<p style="margin:0in 0in 0pt; line-height:normal
<p style="margin:0in 0in 0pt; line-height:normal actually i worked around it and i have found that inserting(in 4.0 only)
<span style="font-size:small; font-family:Calibri transformedDocument=new XmlDocument();
<span style="font-size:small; font-family:Calibri before
using {} will fix this.
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri Y this below code is working fine in 3.5 but not in 4.0? please help me.
<p style="margin:0in 0in 0pt; line-height:normal
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri public void DCLoad(string fileName, XmlDocument docForInitTransform, XmlDocument transformedDocument)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri {
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
if (fileName.ToLower().EndsWith("xsl"))<span style="
<span style="
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
try
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" System.Xml.Xsl.XsltSettings setting = new System.Xml.Xsl.XsltSettings(false, true);
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" System.Xml.XmlUrlResolver res = new System.Xml.XmlUrlResolver();
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" m_xslTransform.Load(fileName, setting, res);
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" if (docForInitTransform != null && transformedDocument != null)
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" {<span style="
<span style="
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style=" <span style="
using (System.Xml.XmlWriter writer = transformedDocument.CreateNavigator().AppendChild())
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" m_xslTransform.Transform(docForInitTransform, null, writer);<span style="
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}<span style="
<span style="
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" }
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
catch (Exception e)
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt 1.25in; text-indent:-81pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" throw new Exception(string.Format("Xsl Loading Error for file: {0}, error message: {1}.", fileName, e.Message), e);
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri }
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri void LoadAllFiles(string sourceDir,string initXml)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri {
<p style="margin:0in 0in 0pt; line-height:normal <span style=" <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style=" XmlDocument
initTransformedDocument = new XmlDocument();
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style=" <span style="
<span style=" XmlDocument initXmlDocument = new XmlDocument();
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
try
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" <span style="
initXmlDocument.Load(initXml);
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
catch{}
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
string [] fileEntries = Directory.GetFiles(sourceDir);
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
foreach(string fileName in fileEntries)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" <span style="
<span style=" DCLoad(fileName, initXmlDocument, initTransformedDocument);
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}<span style="
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri }
Thank u
Madhu
View the full article
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri I got this excption when i tried to run the below piece of code in 4.0
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri "This document already has a DocumentElement node".
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal but the below same code works fine in 3.5. Here im pasting that code. Here im trying to call the DCLoad function for each and every xsl file of a directory.
<p style="margin:0in 0in 0pt; line-height:normal
<p style="margin:0in 0in 0pt; line-height:normal For the first call it is working fine, but when it is calling for the
second time it throws the above exception. Its going smooth in
3.5 but not in 4.0 , is there any specific reason for this?
<p style="margin:0in 0in 0pt; line-height:normal
<p style="margin:0in 0in 0pt; line-height:normal actually i worked around it and i have found that inserting(in 4.0 only)
<span style="font-size:small; font-family:Calibri transformedDocument=new XmlDocument();
<span style="font-size:small; font-family:Calibri before
using {} will fix this.
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri Y this below code is working fine in 3.5 but not in 4.0? please help me.
<p style="margin:0in 0in 0pt; line-height:normal
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri public void DCLoad(string fileName, XmlDocument docForInitTransform, XmlDocument transformedDocument)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri {
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
if (fileName.ToLower().EndsWith("xsl"))<span style="
<span style="
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
try
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" System.Xml.Xsl.XsltSettings setting = new System.Xml.Xsl.XsltSettings(false, true);
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" System.Xml.XmlUrlResolver res = new System.Xml.XmlUrlResolver();
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" m_xslTransform.Load(fileName, setting, res);
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" if (docForInitTransform != null && transformedDocument != null)
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" {<span style="
<span style="
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style=" <span style="
using (System.Xml.XmlWriter writer = transformedDocument.CreateNavigator().AppendChild())
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" m_xslTransform.Transform(docForInitTransform, null, writer);<span style="
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}<span style="
<span style="
<p style="margin:0in 0in 0pt 63pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" }
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
catch (Exception e)
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt 1.25in; text-indent:-81pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" throw new Exception(string.Format("Xsl Loading Error for file: {0}, error message: {1}.", fileName, e.Message), e);
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}
<p style="margin:0in 0in 0pt 22.5pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri }
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri void LoadAllFiles(string sourceDir,string initXml)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri {
<p style="margin:0in 0in 0pt; line-height:normal <span style=" <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style=" XmlDocument
initTransformedDocument = new XmlDocument();
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style=" <span style="
<span style=" XmlDocument initXmlDocument = new XmlDocument();
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
try
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" <span style="
initXmlDocument.Load(initXml);
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
catch{}
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
string [] fileEntries = Directory.GetFiles(sourceDir);
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
foreach(string fileName in fileEntries)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
{
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
<span style=" <span style="
<span style=" DCLoad(fileName, initXmlDocument, initTransformedDocument);
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small <span style="font-family:Calibri <span style="
}<span style="
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:small; font-family:Calibri }
Thank u
Madhu
View the full article