A
accyboy1981
Hi,
I've create a web applicatation the create an xml document dynamically.
Now that is does this I would like to add a stylesheet to the xml
document. I'm using the following code:
XmlDocument doc = new XmlDocument();
XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8",
null);
doc.PrependChild(declaration);
XmlProcessingInstruction objStyleSheet =
doc.CreateProcessingInstruction("xml-stylesheet","");
XmlAttribute objAttType = doc.CreateAttribute("type");
objAttType.Value = "text/css";
XmlAttribute objAttHref = doc.CreateAttribute("href");
objAttHref.Value = "xml.css";
objStyleSheet.Attributes.Append(objAttType);
objStyleSheet.Attributes.Append(objAttHref);
It compiles find however when running it shows the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Source Error:
Line 153: objAttHref.Value = "xml.css";
Line 154:
Line 155: objStyleSheet.Attributes.Append(objAttType);
Line 156: objStyleSheet.Attributes.Append(objAttHref);
Any help would be much appreciated.
Thanks
Simon
I've create a web applicatation the create an xml document dynamically.
Now that is does this I would like to add a stylesheet to the xml
document. I'm using the following code:
XmlDocument doc = new XmlDocument();
XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8",
null);
doc.PrependChild(declaration);
XmlProcessingInstruction objStyleSheet =
doc.CreateProcessingInstruction("xml-stylesheet","");
XmlAttribute objAttType = doc.CreateAttribute("type");
objAttType.Value = "text/css";
XmlAttribute objAttHref = doc.CreateAttribute("href");
objAttHref.Value = "xml.css";
objStyleSheet.Attributes.Append(objAttType);
objStyleSheet.Attributes.Append(objAttHref);
It compiles find however when running it shows the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Source Error:
Line 153: objAttHref.Value = "xml.css";
Line 154:
Line 155: objStyleSheet.Attributes.Append(objAttType);
Line 156: objStyleSheet.Attributes.Append(objAttHref);
Any help would be much appreciated.
Thanks
Simon