473,399 Members | 3,401 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,399 software developers and data experts.

Array Contents to XML

Could anyone give me an example of sending an array's variables to an
XML document all within a subroutine. I'm thinking of a basic example
capturing a form fields values into the array. Help appreciated.

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
1 1017
let the Framework do the work! Load your Array into a DataTable, the DataTable into a DataSet, and use WriteXML..guess I'm just lazy..

here is a quick and dirty:
private void ArrayToXML(object [] YourArray)

{

try

{

DataTable dt = new DataTable("SomeTable");

dt.Columns.Add("ArrayElements");
foreach (object o in YourArray)

{

DataRow dr = dt.NewRow();

dr["ArrayElements"] = o.ToString();

dt.Rows.Add(dr);

}
DataSet ds = new DataSet();

ds.Tables.Add(dt);

ds.WriteXml("C:\\Somefile.xml"); //probably change this

}

catch (Exception ex)

{

//your handling

}

}
Some Inputs :
object [] myArray = {"Hello","this","should","work"};
ArrayToXML(myArray);

will give:

<?xml version="1.0" standalone="yes" ?>
- <NewDataSet>
- <SomeTable>
<ArrayElements>Hello</ArrayElements>
</SomeTable>
- <SomeTable>
<ArrayElements>this</ArrayElements>
</SomeTable>
- <SomeTable>
<ArrayElements>should</ArrayElements>
</SomeTable>
- <SomeTable>
<ArrayElements>work</ArrayElements>
</SomeTable>
</NewDataSet>

Of course you can tweak it as you like...

--
-------------------------------------------------------
http://www.qnal.net/inkabletype

"Steve Bishop" <st****@viper.com> wrote in message news:eD**************@TK2MSFTNGP12.phx.gbl...
Could anyone give me an example of sending an array's variables to an
XML document all within a subroutine. I'm thinking of a basic example
capturing a form fields values into the array. Help appreciated.

Thanks



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2

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

Similar topics

0
by: Row | last post by:
HI, I would first like to say its been about 3 years since looking at java im very rusty! I have to write a post it notes type applet which will function online. (reading from a flat text file)...
6
by: Foxy Kav | last post by:
Hi, another question from me again, i was just wondering if anyone could give me a quick example of reading data from a file then placing the data into an array for some manipulation then reading...
13
by: Mike P | last post by:
I have, what should be, a simple scope problem. Can you help me fix this? I'm trying to end up like this: originalArray = and newArray = . Instead I wind up like this: originalArray = and...
5
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as...
8
by: engaref | last post by:
Hello Every body, I am new with C programming.I have received the Problems from my advisor on Array but I did not find any Proper answer yet. If Possible,please make a solution for the Problems....
5
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through...
2
by: Patrick | last post by:
Hi All, I have numerous files that look like the chunk below. From the date and time I calculate a year day value. For the example that value is 148.67721064815 I'm not an expert yet at...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
7
by: theballz | last post by:
Hi, I am learning c programming and come across a problem i cant seem to solve. I have a file which i wish to parse and put certain lines (which do not contain a hash character) into an array...
2
by: 4Ankit | last post by:
hey guys i am having trouble changing my array code to include a 'for/ in' structure the code i am trying to change is below: <script type="text/javascript"> var contents = new Array(3)
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: 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?
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
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
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...
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...

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.