473,411 Members | 2,184 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,411 software developers and data experts.

Read Xml file in c# and store attribute values in arrays

I had xml file. How to read the xml file in c# and after reading the file we can store the xml attribute names and values are stored in arrays. I am newer to programming language.. So please help me to write the code in c# by using windowsApllications only..

My Xml file is given below..
Expand|Select|Wrap|Line Numbers
  1. <GlobalActivities>
  2.   <Activity Name="LoadImage" LibraryName="Activity.dll" ClassName="Activity.LoadImage" IsDrop="false">
  3.     <Shape Name="LoadImageShape" LibName="DiagramControl.dll" ClassName="LoadImageShape">
  4.     </Shape>
  5.   </Activity>
  6. <Activity Name="SaveImage" LibraryName="Save.Activity.dll" ClassName="Activity.SaveImage" IsDrop="true">
  7.     <Shape Name="SaveImageShape" LibraryName="DiagramControl.dll" ClassName="SaveImageShape">
  8.     </Shape>
  9.   </Activity>
  10. <Activity Name="EditImage" LibraryName="Edit.Activity.dll" ClassName="Activity.EditImage" IsDrop="false">
  11. </Activity>
  12. </GlobalActivity>
In the above code some activities didn't contain shape. In these case shape element is false, so that it is no need to store all shape attribute valus otherwise it store all shape attribute values..
Aug 3 '11 #1
2 3052
What code have you currently got around this?
Aug 4 '11 #2
You're making an assumption that you must store the values somewhere.
If you use the XmlDocument class, all nodes and attributes are accessible as appropriately named collections in the XmlDocument you loaded the file into. No need to convert it into any sort of static arrays.
Expand|Select|Wrap|Line Numbers
  1. using System.Xml;
Then to actually load the file something like this:
Expand|Select|Wrap|Line Numbers
  1. XmlDocument doc = new XmlDocument();
  2. try
  3. {
  4.  doc.Load(FilePath);
  5. }
  6. catch (Exception err)
  7. {
  8.  MessageBox.Show(err.Message);
  9. }
  10.  
Where FilePath is the path to your XML. Then check the attributes of doc.
Aug 12 '11 #3

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

Similar topics

4
by: Vince C. | last post by:
Hi, all. I'd like to know if there's a way to simplify writing attribute values in XSLT. The case is the following: <xsl:template ...> <div id="{ if (@id) @id else generate-id() }">Div...
2
by: Vemund Olstad | last post by:
Hi I have encountered a problem with attribute values in some of my XML files, and I was wondering if anyone here could help out. In some elements in my encoding of some poems I have the TEI...
2
by: Bill Cohagan | last post by:
In my app I'm validating an XML file against an XSD which contains several attribute default value specifications. I'm performing the validation via an xml document load() using a...
0
by: Harley | last post by:
I am trying to write a personal app to keep a bank balance and history. The problem I'm haveing is finding a decent way to store the data on a pocketpc under .net compact framewok useing vb.net....
3
by: Beginner01 | last post by:
I need some help reading in a file that has a column with the student's name and then a column with their score. I need to input this into 2 seperate arrays. One for the names and one for the...
7
by: =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= | last post by:
How do I split a title attribute value into lines within the source code so that the paragraph gets reassembled by the browser when it is being displayed? Microsoft Internet Explorer 7 preserves...
1
by: passpass | last post by:
I am having a problem in reading the XML file 1. I need to read all attribute of a node as well as child node too if there exist any. 2. I need values of these corresponding attributes too if...
4
by: carmelo | last post by:
Hi! I need to read and store data from a file, but I don't the name of it; Is this code correct and is there a better way to do this thing?? int main() { cout << " type file name:" char *...
7
by: andyehi | last post by:
Hi Everyone, I am having a txt file config.txt on application start up path.I need to read that file line by line using a delimiter ; or , and store the values in a variable to connect to the...
3
by: nady | last post by:
Dear Techies, I have a code which retrieves values from database cmdSelect = New OleDbCommand("select fields,finesFields from trafficReport where checked LIKE 1", conn) cmdSelectDr =...
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...
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
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...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...

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.