Hi,
I am trying to transform an xml file to wml using asp.net. I get the xml file from sql server as a string. so I need to convert it to xml and tranform that xml file to wml.
Here is my code:
private void XmlTransformToWML(string hn_xml)
{
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.LoadXml(hn_xml);
}
catch (XmlException e)
{
Response.Write(e.Message);
}
XPathDocument xpathDoc = new XPathDocument();
string xslPath = Server.MapPath("hnxml.xslt");
XslCompiledTransform myXslTrans = new XslCompiledTransform();
//Load the XSL stylsheet into the XslCompiledTransform object
myXslTrans.Load(xslPath);
myXslTrans.Transform(xmlDoc, null, Response.Output);
}
My problem is when I execute this code I am getting the following exception. I have a doubt, can we use XmlDocument as a argument to transform to wml.
Exception:
System.Xml.Xsl.XslTransformException: Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added. at System.Xml.Xsl.Runtime.XmlQueryOutput.ThrowInvalidStateError(XPathNodeType constructorType) at System.Xml.Xsl.Runtime.XmlQueryOutput.ConstructInEnumAttrs(XPathNodeType rootType) at System.Xml.Xsl.Runtime.XmlQueryOutput.WriteStartAttribute(String prefix, String localName, String ns) at System.Xml.Xsl.Runtime.XmlQueryOutput.WriteStartAttributeLocalName(String localName) at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current) at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current) at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current) at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current) at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator ) at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter) at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results) at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) at topic.XmlTransformToWML(String hn_xml) in d:\Thesis\Thesis Documentation\Codes From Fuchs\Original HNXML\Mobile Applications\topic.aspx.cs:line 71 at topic.Page_Load(Object sender, EventArgs e) in d:\Thesis\Thesis Documentation\Codes From Fuchs\Original HNXML\Mobile Applications\topic.aspx.cs:line 40
Any ideas would be appreaciated.
Thanks
Aruna.G
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).