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

Can an XML file be converted into a valid DataSource?

Sky
What makes something a valid DataSource? What methods/iterators/etc?

Why do I ask?
I do understand that a DataSet is based on an XML structure...but it's too
table structured for what I am thinking...
Can one read in a an xml file that has various embedded nodes (ie: records
that have children records as XML does best) -- possibly not all the same
length (ie, dif 'column count' for certain 'rows') and try to shove that
into a DataRepeater?

In other words, if I were trying to make a TreeList (Tree with several
columns) based on a DataRepeater, could I read from an XML file? Or do I
have to convert the XML file node by node into a DataSet first?

PS: If anybody has links to someone who has tried this approach, or
similar -- love to hear where!

Best,
Sky
Nov 18 '05 #1
5 1747
If you XML is not too complicated then you can directly bind your xml as
datasource. Check out this article for more details
http://www.extremeexperts.com/Net/Ar...oDataGrid.aspx

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com

"Sky" <ne********@nospam.xact-solutions.com> wrote in message
news:eL**************@TK2MSFTNGP11.phx.gbl...
What makes something a valid DataSource? What methods/iterators/etc?

Why do I ask?
I do understand that a DataSet is based on an XML structure...but it's too
table structured for what I am thinking...
Can one read in a an xml file that has various embedded nodes (ie: records
that have children records as XML does best) -- possibly not all the same
length (ie, dif 'column count' for certain 'rows') and try to shove that
into a DataRepeater?

In other words, if I were trying to make a TreeList (Tree with several
columns) based on a DataRepeater, could I read from an XML file? Or do I
have to convert the XML file node by node into a DataSet first?

PS: If anybody has links to someone who has tried this approach, or
similar -- love to hear where!

Best,
Sky

Nov 18 '05 #2
To answer your first question,

Anything that implements the IEnumerable interface.
http://msdn.microsoft.com/library/de...classtopic.asp

"Sky" <ne********@nospam.xact-solutions.com> wrote in message
news:eL**************@TK2MSFTNGP11.phx.gbl...
What makes something a valid DataSource? What methods/iterators/etc?

Why do I ask?
I do understand that a DataSet is based on an XML structure...but it's too
table structured for what I am thinking...
Can one read in a an xml file that has various embedded nodes (ie: records
that have children records as XML does best) -- possibly not all the same
length (ie, dif 'column count' for certain 'rows') and try to shove that
into a DataRepeater?

In other words, if I were trying to make a TreeList (Tree with several
columns) based on a DataRepeater, could I read from an XML file? Or do I
have to convert the XML file node by node into a DataSet first?

PS: If anybody has links to someone who has tried this approach, or
similar -- love to hear where!

Best,
Sky

Nov 18 '05 #3
Sky
You're a godsend Saravana! The following is just what I needed!
Understanding that the doc is not IEnumerable -- but a returned collection
is -- is just the missing piece I was looking for!

Dim oXML As New XmlDataDocument
oXML.Load(Server.MapPath("product.xml"))
DataGrid1.DataSource = oXML.SelectNodes("DataSet/Product")
DataGrid1.DataBind()

This leads me try to see into the future : if I want to take this further
and make a DataRepeater based TreeList from this (see moanings looking for a
good TreeList (Tree w/multiple columns) in messages further down...) I would
have to do some kind of recursive DataRepeater that binds that may look
something like:

void RenderNode(oNode){
oSet = oNode.SelectNodes("child::*");
...hum...somewhere around here I am lost...
...but it would somehow look like attaching to a datarepeater that
ejects a div with spans in it...

...but the next part to reiterate would be
foreach (oSubNode in oSet){
RenderNode(oSubNode);
}

}

//How's that for totally unclear, lost, proxy code!!! (I'm having such
trouble getting a grip on ASP.NET some days, it really isn't funny!)
//Any ideas on how to make this make sense in any way???

"Saravana [MVP]" <sa******@sct.co.in.nospam> wrote in message
news:ea**************@TK2MSFTNGP10.phx.gbl...
If you XML is not too complicated then you can directly bind your xml as
datasource. Check out this article for more details
http://www.extremeexperts.com/Net/Ar...oDataGrid.aspx

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com

"Sky" <ne********@nospam.xact-solutions.com> wrote in message
news:eL**************@TK2MSFTNGP11.phx.gbl...
What makes something a valid DataSource? What methods/iterators/etc?

Why do I ask?
I do understand that a DataSet is based on an XML structure...but it's too table structured for what I am thinking...
Can one read in a an xml file that has various embedded nodes (ie: records that have children records as XML does best) -- possibly not all the same length (ie, dif 'column count' for certain 'rows') and try to shove that into a DataRepeater?

In other words, if I were trying to make a TreeList (Tree with several
columns) based on a DataRepeater, could I read from an XML file? Or do I
have to convert the XML file node by node into a DataSet first?

PS: If anybody has links to someone who has tried this approach, or
similar -- love to hear where!

Best,
Sky


Nov 18 '05 #4
Sky
"One last question":
What happens when you bind an IEnumerable datasource to a control...but it's
missing parts of it?

What I mean is what would happen if you bind as the article suggests but the
xml datasource looks like (missing some fields from some of the records):

<?xml version="1.0" standalone="yes"?>
<DataSet>
<Product>
<Name>Onida TV</Name>
<ProductID>1</ProductID>
<Price>12000</Price>
<Quantity>2</Quantity>
</Product>
<Product>
<Name>Samsung TV</Name>
<ProductID>2</ProductID>
</Product>
<Product>
<Name>LG TV</Name>
<ProductID>3</ProductID>
</Product>
</DataSet>

According to me, this would cause a big fat exception. How would you trap,
replace with a 0, and move on to next field? Since about the last access to
the code is at

try {
Grid=oNode.selectNodes("child::*")
}
catch {}

it would just abort/rollback all the binding... how to trap down at a more
granular method, at the cell(field)-binding level?

Any suggestions?
Or definatly not possible?

Thanks,
Sky

"Sky" <ne********@nospam.xact-solutions.com> wrote in message
news:eL**************@TK2MSFTNGP11.phx.gbl...
What makes something a valid DataSource? What methods/iterators/etc?

Why do I ask?
I do understand that a DataSet is based on an XML structure...but it's too
table structured for what I am thinking...
Can one read in a an xml file that has various embedded nodes (ie: records
that have children records as XML does best) -- possibly not all the same
length (ie, dif 'column count' for certain 'rows') and try to shove that
into a DataRepeater?

In other words, if I were trying to make a TreeList (Tree with several
columns) based on a DataRepeater, could I read from an XML file? Or do I
have to convert the XML file node by node into a DataSet first?

PS: If anybody has links to someone who has tried this approach, or
similar -- love to hear where!

Best,
Sky

Nov 18 '05 #5
Sky
Dear Michael:
In regards to my question "what qualifies something as iEnumerable and
therefore a valid datasource", turns out that when I did a search of my code
I must have already investigated (and promptly forgot!) how to make an
IEnumerable object... So, with your reminder, and the piece of code that i
found, case [almost] closed, thanks!!!

My only remaining question is making it IEnumerable, does this really do ALL
that is required to qualify it as a Valid datasource for eg:DataGrid,
etc. -- and what happens when a 'piece' (a field) is missing from the source
(what I mean by this is if you define an xml recordset as a DataSource to eg
a DataGrid -- but some of the records are incomplete and are missing
sub-node/fields in some cases). What happens? Exception? If so, any way that
it can be trapped/corrected, and move on to next fields and rows?

Sky


PS:
Code found was (for anybody who can use it when reading these posts)
Turns out that the "Recipe" is really simple: you only have to enherit from
IEnumerable, and overload the base.GetEnumerator() and MoveNext() and
Current property . No sweat:
public class cSchemaInfoColumnCollection : System.Collections.IEnumerable

{

private System.Collections.Hashtable _List = new
System.Collections.Hashtable();

public cSchemaInfoColumn this[string qName]

{

get

{

return (cSchemaInfoColumn)_List[qName.ToLower()];

}

set

{

_List[qName.ToLower()] = value;

}

}

/*----------*/

public cMyEnumerator GetEnumerator()

{

return new cMyEnumerator(_List);

}

/*----------*/

// Implement the GetEnumerator() method:

System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator()

{

return GetEnumerator();

}

/*----------*/

/*----------*/

/*----------*/

// Declare the enumerator and implement the IEnumerator interface:

public class cMyEnumerator: System.Collections.IEnumerator

{

int nIndex;

System.Collections.Hashtable _List;

string[] tKeys;

/*----------*/

public cMyEnumerator(System.Collections.Hashtable qList)

{

_List = qList;

tKeys = new string[_List.Count];

_List.Keys.CopyTo(tKeys,0);

;

nIndex = -1;

}

/*----------*/

public void Reset()

{

nIndex = -1;

}

/*----------*/

public bool MoveNext()

{

nIndex++;

return(nIndex < tKeys.Length);

}

/*----------*/

// The current property on the IEnumerator interface:

object System.Collections.IEnumerator.Current

{

get

{

return(Current);

}

}

/*----------*/

public cSchemaInfoColumn Current

{

get

{

return((cSchemaInfoColumn)_List[tKeys[nIndex]]);

}

}

/*----------*/

}

}


"Michael" <raterus@localhost> wrote in message
news:uy**************@TK2MSFTNGP09.phx.gbl...
To answer your first question,

Anything that implements the IEnumerable interface.
http://msdn.microsoft.com/library/de...classtopic.asp
"Sky" <ne********@nospam.xact-solutions.com> wrote in message
news:eL**************@TK2MSFTNGP11.phx.gbl...
What makes something a valid DataSource? What methods/iterators/etc?

Why do I ask?
I do understand that a DataSet is based on an XML structure...but it's too table structured for what I am thinking...
Can one read in a an xml file that has various embedded nodes (ie: records that have children records as XML does best) -- possibly not all the same length (ie, dif 'column count' for certain 'rows') and try to shove that into a DataRepeater?

In other words, if I were trying to make a TreeList (Tree with several
columns) based on a DataRepeater, could I read from an XML file? Or do I
have to convert the XML file node by node into a DataSet first?

PS: If anybody has links to someone who has tried this approach, or
similar -- love to hear where!

Best,
Sky


Nov 18 '05 #6

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

Similar topics

0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
68
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
80
by: nicolas.sitbon | last post by:
Hi everybody, in a french C book, the author says that only {fgetc, getc, getchar, fgetwc, getwc, getwchar, fgets, gets, fgetws, getws, fputc, putc, putchar, fputwc, putwc, putwchar, fputs, puts,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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...

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.