CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Location
    Norway
    Posts
    120

    Two Questions on XMLDataSource (ADO.NET)

    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

    Code:
    <?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?

  2. #2
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Two Questions on XMLDataSource (ADO.NET)

    Quote Originally Posted by Efitap
    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

    Code:
    <?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
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  3. #3
    Join Date
    Oct 2005
    Location
    Norway
    Posts
    120

    Re: Two Questions on XMLDataSource (ADO.NET)

    Quote Originally Posted by cjard
    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.

    Quote Originally Posted by cjard
    Note that Name and name are NOT the same in xml
    Yeah, I am aware of that

    Quote Originally Posted by cjard
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured