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

Working with an Embedded XML File

Hello all,
I have a basic XML file of which I set the Build Action to "Embedded
Resource" The XML file is simple:

<root>
<item>
<name>Test Name</name>
<description>Test Description</description>
</item>
</root>

I'm having a heck of a time reading the xml file embedded in the assembly.
I'm more than certain that I'm missing some sort of name space element in
the XML.. I've searched high and low and I am unable to find any sample
code that works. I get errors such as invalid object, etc.

I was hoping that somebody might be able to refer me to a url that explains
how to create the xml file correctly and the code to read the embedded xml
file.

C# and vb.net examples are welcome.

Thanks in advance.

Jay

Nov 12 '05 #1
2 19424
If you've compiled the XML file as an embedded resource then you can do
something like this:
using System;
using System.IO;
using System.Reflection;
using System.Xml;

class Application
{
static void Main(string[] args) {

Stream s =
Assembly.GetExecutingAssembly().GetManifestResourc eStream("CSharpConsole.XML
File1.xml");

XmlDocument xdoc = new XmlDocument();

StreamReader reader = new StreamReader(s);

xdoc.LoadXml(reader.ReadToEnd());

reader.Close();

}
}

or:

Imports System.Xml
Imports System.Reflection
Imports System.IO

Module Main

Sub Main()

Dim s As Stream =
Assembly.GetExecutingAssembly().GetManifestResourc eStream("XMLFile1.xml")

Dim xdoc As New XmlDocument

Dim reader As New StreamReader(s)

xdoc.LoadXml(reader.ReadToEnd())

reader.Close()

End Sub

End Module

Notice in C# you have to prepend the project name (this is not a namespace)
to the file name. IIRC this is due to the way the VB compiler stores
resources in the assembly.

--
Klaus H. Probst, MVP
http://www.vbbox.com/
"Jay Douglas" <RE*****************@squarei.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello all,
I have a basic XML file of which I set the Build Action to "Embedded
Resource" The XML file is simple:

<root>
<item>
<name>Test Name</name>
<description>Test Description</description>
</item>
</root>

I'm having a heck of a time reading the xml file embedded in the assembly.
I'm more than certain that I'm missing some sort of name space element in
the XML.. I've searched high and low and I am unable to find any sample
code that works. I get errors such as invalid object, etc.

I was hoping that somebody might be able to refer me to a url that explains how to create the xml file correctly and the code to read the embedded xml
file.

C# and vb.net examples are welcome.

Thanks in advance.

Jay

Nov 12 '05 #2
Perfect.

Thanks a ton.
"Klaus H. Probst" <us*******@vbbox.com> wrote in message
news:eg**************@TK2MSFTNGP12.phx.gbl...
If you've compiled the XML file as an embedded resource then you can do
something like this:
using System;
using System.IO;
using System.Reflection;
using System.Xml;

class Application
{
static void Main(string[] args) {

Stream s =
Assembly.GetExecutingAssembly().GetManifestResourc eStream("CSharpConsole.XML File1.xml");

XmlDocument xdoc = new XmlDocument();

StreamReader reader = new StreamReader(s);

xdoc.LoadXml(reader.ReadToEnd());

reader.Close();

}
}

or:

Imports System.Xml
Imports System.Reflection
Imports System.IO

Module Main

Sub Main()

Dim s As Stream =
Assembly.GetExecutingAssembly().GetManifestResourc eStream("XMLFile1.xml")

Dim xdoc As New XmlDocument

Dim reader As New StreamReader(s)

xdoc.LoadXml(reader.ReadToEnd())

reader.Close()

End Sub

End Module

Notice in C# you have to prepend the project name (this is not a namespace) to the file name. IIRC this is due to the way the VB compiler stores
resources in the assembly.

--
Klaus H. Probst, MVP
http://www.vbbox.com/
"Jay Douglas" <RE*****************@squarei.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello all,
I have a basic XML file of which I set the Build Action to "Embedded
Resource" The XML file is simple:

<root>
<item>
<name>Test Name</name>
<description>Test Description</description>
</item>
</root>

I'm having a heck of a time reading the xml file embedded in the assembly. I'm more than certain that I'm missing some sort of name space element in the XML.. I've searched high and low and I am unable to find any sample
code that works. I get errors such as invalid object, etc.

I was hoping that somebody might be able to refer me to a url that

explains
how to create the xml file correctly and the code to read the embedded xml file.

C# and vb.net examples are welcome.

Thanks in advance.

Jay


Nov 12 '05 #3

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

Similar topics

1
by: james | last post by:
What class / method should I be using to get the full path to an embedded resource ? In my case I have an .xml file that my app uses, it is set as embedded resource, and I have a control that...
4
by: Patrick Blackman | last post by:
I have a text file embedded in my dll, how can I load that file without using the GetManifestResourceStream of the Assembly class, I want to read it as if it was just located in my c:\my document...
10
by: Minh | last post by:
I search in all the Disscussion but can not found. How can I create a MS Access Database file using C# code with a given Table Structure ? For example, I want to create a Access Database File...
4
by: Axter | last post by:
Sorry for OT question, but does any one have a working *.bat file to get Comeau to work with VC++ 7.1, VC++ 8.0, or GNU 3.x compilers. I've tried everything I can think off, to get it to work,...
5
by: Max | last post by:
hi i have file browser control to select any file and a button to upload file on my web page now when i select any file. now on click of upload button i have check that file exist or no if...
0
by: satish | last post by:
Hi, I have an issue ..i have a text which has the information of 4 test files and they are placed in the order 4 --- this number says (total no of text files) File1 1370 -- Memory of the text...
0
by: andreas2411 | last post by:
Hi, I have a file which I would like to put on the clipboard so that it is pasted in Word or WordPad the file appears as an embedded file. I can use the RichTextBox to generate RichText with...
2
Frinavale
by: Frinavale | last post by:
I am attempting to use embedded resources in an Ajax Enabled ASP.NET Web Application. I'm using Visual Studio 2008 and VB.NET server side code. The project is called "EmbeddedResources" with the...
8
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to...
0
by: Belsirk | last post by:
Hi, i'm using C# Visual Studio 2008 for made a apps able to take some information from the app and sending them to a excel template, i'm using Microsoft.Office.Interop.Excel namespace and i don't...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.