Click to See Complete Forum and Search --> : Two Questions on XMLDataSource (ADO.NET)


Efitap
April 14th, 2008, 01:04 AM
Forgive me if this has already been answered, I've searched on various terms, but it is difficult to formulate the problem properly, and the search results have not given me anything that I can work with yet, so I ask here.

given the xml


<?xml version="1.0" encoding="UTF-8"?>
<Persons>
<Person>
<Name>Papa</Name>
<ShoeNumber>43</ShoeNumber>
</Person>
<Person>
<Name>Neo</Name>
<ShoeNumber>43</ShoeNumber>
</Person>
<Person>
<Name>Andersson</Name>
<ShoeNumber>47</ShoeNumber>
<Profession>Shark</Profession>
</Person>
</Persons>


I have two challenges:

1) I cannot connect this XML directly to a dataGrid using a data binder object as I can with an SqlDataSource. The problem seems to be that the xml does not contain attribute values, rather, it has text node values, such as <Name>someone</Name> instead of <Person name="someone" />
First question is: Did I miss something during my xml reading, or is this a limitation from Microsoft's part?

2) I would like to make a web application where a user can upload an xml log and get reasonable information back from it, but there is a catch! The xml export that the user is uploading (xml report from SeaPine TestTrack if you know it) does not always contain all possible node values, as is the example with person xml above, I have intentionally only included the node "Profession" on the last Person node. Now, still in the spirit of attempting to use XmlDataObject, databinder, and datagrid, is it at all possible to accomplish this with basically the drag-n-drop functionality that the SQL objects support?

cjard
April 14th, 2008, 06:21 AM
Forgive me if this has already been answered, I've searched on various terms, but it is difficult to formulate the problem properly, and the search results have not given me anything that I can work with yet, so I ask here.

given the xml


<?xml version="1.0" encoding="UTF-8"?>
<Persons>
<Person>
<Name>Papa</Name>
<ShoeNumber>43</ShoeNumber>
</Person>
<Person>
<Name>Neo</Name>
<ShoeNumber>43</ShoeNumber>
</Person>
<Person>
<Name>Andersson</Name>
<ShoeNumber>47</ShoeNumber>
<Profession>Shark</Profession>
</Person>
</Persons>


I have two challenges:

1) I cannot connect this XML directly to a dataGrid using a data binder object as I can with an SqlDataSource. The problem seems to be that the xml does not contain attribute values, rather, it has text node values, such as <Name>someone</Name> instead of <Person name="someone" />
First question is: Did I miss something during my xml reading, or is this a limitation from Microsoft's part?
Doesnt make sense. The xml readers I have seen do not draw a distinction between an element and an attribute in this context
Note that Name and name are NOT the same in xml


2) I would like to make a web application where a user can upload an xml log and get reasonable information back from it, but there is a catch! The xml export that the user is uploading (xml report from SeaPine TestTrack if you know it) does not always contain all possible node values, as is the example with person xml above, I have intentionally only included the node "Profession" on the last Person node. Now, still in the spirit of attempting to use XmlDataObject, databinder, and datagrid, is it at all possible to accomplish this with basically the drag-n-drop functionality that the SQL objects support?
Mmhh, yeah thats why I'd recommend that you use the XSD tool and a full example XML to create either a set of classes or a dataset.. You can then further tweak that, and deserialize it or read it itno a dataset.

For a quick and nasty version, simply make a new dataset and call the ReadXml() passing in a stream or filename to read from. Your dataset will end up with a datatable called Person, having 3 rows and 3 columns. Two of the rows will have a null profession. If the node existed but was empty, they would have an String.Empty value for the profession

Efitap
April 15th, 2008, 12:17 AM
Doesnt make sense. The xml readers I have seen do not draw a distinction between an element and an attribute in this context

That is my belief too, but still, I was unable to give the simplest of examples to a collegue when asked, so I was kind of.. stumped :) Could it be that my computer is lacking something in particular? It should be as easy as:
1 - define an XML data source pointing to the xml file
2 - create an xml data binder
3 - associate the xml data binder with the data grid, i.e on page load.

Only works with attributes though, not node values.


Note that Name and name are NOT the same in xml

Yeah, I am aware of that :)


For a quick and nasty version, simply make a new dataset and call the ReadXml() passing in a stream or filename to read from. Your dataset will end up with a datatable called Person, having 3 rows and 3 columns. Two of the rows will have a null profession. If the node existed but was empty, they would have an String.Empty value for the profession
I'll try that, thanks :)