473,656 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.CreateXmlDe claration("1.0" , "UTF-8",
null);

doc.PrependChil d(declaration);

XmlProcessingIn struction objStyleSheet =
doc.CreateProce ssingInstructio n("xml-stylesheet","") ;

XmlAttribute objAttType = doc.CreateAttri bute("type");
objAttType.Valu e = "text/css";

XmlAttribute objAttHref = doc.CreateAttri bute("href");
objAttHref.Valu e = "xml.css";

objStyleSheet.A ttributes.Appen d(objAttType);
objStyleSheet.A ttributes.Appen d(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.NullRefe renceException: Object reference not
set to an instance of an object.

Source Error:
Line 153: objAttHref.Valu e = "xml.css";
Line 154:
Line 155: objStyleSheet.A ttributes.Appen d(objAttType);
Line 156: objStyleSheet.A ttributes.Appen d(objAttHref);

Any help would be much appreciated.

Thanks

Simon

Jul 13 '06 #1
1 1282
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


"accyboy198 1" 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.CreateXmlDe claration("1.0" , "UTF-8",
null);

doc.PrependChil d(declaration);

XmlProcessingIn struction objStyleSheet =
doc.CreateProce ssingInstructio n("xml-stylesheet","") ;

XmlAttribute objAttType = doc.CreateAttri bute("type");
objAttType.Valu e = "text/css";

XmlAttribute objAttHref = doc.CreateAttri bute("href");
objAttHref.Valu e = "xml.css";

objStyleSheet.A ttributes.Appen d(objAttType);
objStyleSheet.A ttributes.Appen d(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.NullRefe renceException: Object reference not
set to an instance of an object.

Source Error:
Line 153: objAttHref.Valu e = "xml.css";
Line 154:
Line 155: objStyleSheet.A ttributes.Appen d(objAttType);
Line 156: objStyleSheet.A ttributes.Appen d(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
3855
by: Newgene | last post by:
Hi, group, I am trying to dynamically add a method to class by following this post: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/2ec2ad7a0a5d54a1/928e91be352c6bfc?q=%22new.code(%22+%22import+new&_done=%2Fgroup%2Fcomp.lang.python%2Fsearch%3Fgroup%3Dcomp.lang.python%26q%3D%22new.code(%22+%22import+new%26qt_g%3D1%26&_doneTitle=Back+to+Search&&d#928e91be352c6bfc But I got the Error like the below: ...
6
2941
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 script created them. It used things like parentnode, insertBefore, appendChildNode,... Any ideas/direction is appreciated.
3
2382
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 and I would like to populate certain fields with client names and account data. Also, I would like to make a "master" PDF that contains all the PDF summaries in one document -- and use bookmarks if possible.
3
2867
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: value Stack trace is showing the error in OnDataBinding event, which I don't hook in the cases where I'm getting this error ArgumentOutOfRangeException: Specified argument was out of the range of valid values Parameter name: value...
16
9767
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: Run-time error '-2147024894 (80070002)': File or assembly name COMTest3, or one of its dependencies, was not found. The code for the COM:
4
3641
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 and reaches a specific length, it terminates printing that page, prints a page number, and then begins to print the next page using the same header and format as the previous page. The page uses no tables or paragraph elements, only CSS. IOW, I...
6
1491
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 subroutine on postback. To me it seems like the button click event looks for a client script instead of going to the aspx codepage and execute the sub there. The same thing happens with textboxes, where I programatically add
1
4889
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 set text boxes and labels inside the table rows. I then added a button. All of these are done through code. The problem that i am having is i can get the value from a text box with resides inside the first panel (out side of panel that is...
7
6651
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 tabcontainer which has 1 panel already, however I want to try create the TabPanels dynamically. I followed the advice here: http://www.asp.net/learn/ajax-videos/video-156.aspx (3rd comment - Joe Stagner)
0
8382
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.