473,388 Members | 1,526 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,388 software developers and data experts.

create xml file from xml stored in a DB

maylortaylor
72 64KB
I have a table in my database that has a 3 fields.

RuleID | RuleName | Rule

the ruleID is a randomly generated string of characters, RuleName is the name the user gives to the rule, and the Rule field is about 600 characters long and is just XML text.

I want to read that Rule field from the database and use it inside the function below.

Expand|Select|Wrap|Line Numbers
  1. private static List<MenuItem> LoadRules(bool evaluationType)
  2.         {
  3.             //string path = HttpContext.Current.Server.MapPath(string.Format("/Rules/{0}/{1}/", ip, evaluationType ? "Evaluation" : "Execution"));
  4.             List<MenuItem> list = new List<MenuItem>();
  5.             //if(Directory.Exists(path))
  6.             {
  7.                 //foreach(string file in Directory.GetFiles(path))
  8.                 {
  9.                     XmlDocument xml = new XmlDocument();
  10.  
  11.                     xml.Load(file);
  12.                     XmlNamespaceManager m = new XmlNamespaceManager(xml.NameTable);
  13.                     m.AddNamespace("x", xml.DocumentElement.NamespaceURI);
  14.                     XmlNode rule = xml.SelectSingleNode("/x:codeeffects/x:rule", m);
  15.                     list.Add(new MenuItem(
  16.                         rule.Attributes["id"].Value,
  17.                         rule.SelectSingleNode("x:name", m).InnerText,
  18.                         rule.SelectSingleNode("x:description", m) == null ? null : rule.SelectSingleNode("x:description", m).InnerText));
  19.                 }
  20.             }
  21.             return list;
  22.         }
This function loads an xml file from a static location and parses out some information to a context menu.

BUt i'm culeless on how to have the function read the xml info found inside my database.

I'm a rookie at C# so be gentle
May 15 '13 #1
1 1566
maylortaylor
72 64KB
Ok, i got part of it figured out but now i'm getting some "object refernce" error.

Expand|Select|Wrap|Line Numbers
  1. private static List<MenuItem> LoadRules(bool evaluationType)
  2.         {
  3.             string path = HttpContext.Current.Server.MapPath(string.Format("/Rules/{0}/{1}/", ip, evaluationType ? "Evaluation" : "Execution"));
  4.             string xmlstring = LoadRuleXmlFromDB();
  5.             File.WriteAllText(path + "rule.xml", xmlstring);
  6.  
  7.             List<MenuItem> list = new List<MenuItem>();
  8.             //if(Directory.Exists(path))
  9.             {
  10.                 foreach(string file in Directory.GetFiles(path))
  11.                 {
  12.  
  13.                     XmlDocument xml = new XmlDocument();
  14.                     xml.Load(file);
  15.                     XmlNamespaceManager m = new XmlNamespaceManager(xml.NameTable);
  16.                     m.AddNamespace("x", xml.DocumentElement.NamespaceURI);
  17.                     XmlNode rule = xml.SelectSingleNode("/x:codeeffects/x:rule", m);
  18.                     list.Add(new MenuItem(
  19.                         rule.Attributes["id"].Value,
  20.                         rule.SelectSingleNode("x:name", m).InnerText,
  21.                         rule.SelectSingleNode("x:description", m) == null ? null : rule.SelectSingleNode("x:description", m).InnerText));
  22.                 }
  23.             }
  24.             return list;
  25.         }
As you can see, i created a string xmlstring, loaded my xml from the DB into the string, then wrote the string to a 'rule.xml' file.

But now, i'm getting "object reference not set to an instance of an object" once the code gets to the
Expand|Select|Wrap|Line Numbers
  1. list.Add(new MenuItem(
  2.                         rule.Attributes["id"].Value,
  3.                         rule.SelectSingleNode("x:name", m).InnerText,
  4.                         rule.SelectSingleNode("x:description", m) == null ? null : rule.SelectSingleNode("x:description", m).InnerText));
part.

Upon further probing, i have found that the "rule" is null. Not sure why this is happening.
May 15 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Abdulla Herzallah | last post by:
Hi every one I have tried to search for any links, hints clues on how to create a Stored Procedure programmatically using C# but came back with empty handed :-( I know it is definitly possible...
1
by: shumaker | last post by:
IF I have a very simple query, something like SELECT COLUMNNAME FROM TABLE and I know I will use it at least in a few different places, then would it be good design to create a stored procedure...
1
by: Dino M. Buljubasic | last post by:
How can I get date stamp of a file stored on an FTP server from a VB.net application? Thank you, -- Dino Buljubasic Software Developer http://rivusglobal.com
13
by: Dino Buljubasic | last post by:
I want to get the size of a file stored in SQL Database (as image data type). Anybody knows how to do this? Any help will be greatelly appreciated
0
by: dphill | last post by:
Hello all I am a beginner .Net programmer so please forgive my ignorance. In brief, I am trying to read from xml file stored in a SQL database table’s field. This is what I used to create...
0
by: MKH | last post by:
Greetings, OS = Windows 2000 Server SP4 SQL = MS SQL 2000 Server SP4 Language = T-SQL I have an excel file stored in a data base table as an image data type. I would like to somehow...
2
by: =?Utf-8?B?UHVjY2E=?= | last post by:
I need to retrieve and open a file stored on a Unix server on a network and opens the file as a delimited text file. I'm using VS2005, .net 2.0 and C#. What's the best way to do this and if...
0
by: mabeljovan | last post by:
Hi! I'm new in this forum how to create a stored procedure that will be called to load a csv file then put some filter to update if duplicate and insert if not existing? how can i do this? ...
1
by: rishhh | last post by:
How do I create a stored procedure in Access database? When i try using the CREATE PROCEDURE Statement in a Query Object, it gives me a sytax error. Is there any other way of creating a procedure? ...
2
by: sweetsecret | last post by:
Create a stored procedure that prints the list of the locations(location_id,street_address,city,country_name) from the locations table sorted by location id in ascending order along with the total...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.