473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Dynamically Creating XML Documents Error

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

Jul 13 '06 #1
1 1272
It may be that you just have a syntax error in a part of your code. You
should be expecting a finished product like so:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet href="http://www.blogger.com/styles/atom.css"
type="text/css"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"accyboy1981" wrote:
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

Jul 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Newgene | last post by:
Hi, group, I am trying to dynamically add a method to class by following this post: ...
6
by: NotGiven | last post by:
I want to learn moer of what I saw in a recent example. They create a page that created new fields/element. It's not like they were hidden and they displayed them, they were not there, then the...
3
by: Null | last post by:
Hello -- I am looking for a way to dynamically generate PDF documents - combining Crystal Reports and data driven "fields". For example, I have a template that's essentially a summary document...
3
by: John Crowley | last post by:
I've run into a problem where drop down lists are refusing to data bind with the following error on the DataBind() call Specified argument was out of the range of valid values. Parameter name:...
16
by: Asaf | last post by:
I am trying to create and use a COM object with C#.NET 2005. The assembly is set to "Register for COM interop" but when I am trying to call it from VB on Word 2003 I am getting this error: ...
4
by: Ed Jay | last post by:
I generate a DHTML page (a medical report) with dynamically generated text based on user input (answers to questions). The page length changes dynamically. I desire that when the page is printed...
6
by: Bjorn Sagbakken | last post by:
Hello In VS2005: I am adding buttons and textboxes dynamically into a table, that also dynamically expands. So far, so good, actually very nice. But I am having trouble starting the desired...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.