XmlDataDocument

  • Thread starter Thread starter Random
  • Start date Start date
R

Random

I'm trying to get the XmlDataDocument to work. What I'm doing is creating a
root node, and then importing in nodes from different xml sources to
contruct a brand new document. However, when I then go to access the Tables
in the DataSet, there is nothing there. All of the samples I've seen have
the XmlDataDocument.DataSet being loaded from a physical *.xml file. Why
can't I get the DataSet to populate with the information that's already in
the XmlDataDocument?
 
well i have used xmldatadocument in past and i have used both static xml
content in file and dynamincally using xml from nodes.
can you post your code snippet ?

what i suggest you do is

1. declare DataSet
2. declare XmlDataDocument with binding to the DataSet declared in step 1
3. go about populating your XmlDataDocument with your nodes
4. read the DataSet.

--

Regards,

Hermit Dave (D'way)
http://hdave.blogspot.com
 
Alright, here's a good example of the XML...

<searchable_xml>
<unit filename="firstunit.xml">
<sections>
<section category="A">
<paragraph dbidx="10">just some text that will be
searchable</paragraph>
<paragraph dbidx="11">more text that will be
searchable</paragraph>
<bullet dbidx="12">part of a searchable bulleted
list</bullet>
<bullet dbidx="13">more of a searchable bulleted
list</bullet>
</section>
<section category="B">
[...more <paragraph/> and <bullet/> elements
</section>
</sections>
<areas>
<area category="Q" subcategory="Q2">
[...more <paragraph/> and <bullet/> elements
</area>
<area category="R" subcategory="R2">
[...more <paragraph/> and <bullet/> elements
</area>
</areas>
</unit>
<unit filename="secondunit.xml">
<sections>
<section category="C">
[...more <paragraph/> and <bullet/> elements
</section>
<section category="D">
[...more <paragraph/> and <bullet/> elements
</section>
</sections>
<areas>
<area category="Q" subcategory="Q2">
[...more <paragraph/> and <bullet/> elements
</area>
<area category="R" subcategory="R2">
[...more <paragraph/> and <bullet/> elements
</area>
</areas>
</unit>
</searchable_xml>

My goal, after having constructed this "master" XML document within the
XmlDataDocument, is to bind it to a Web Control (not sure which one is the
most appropriate yet) with one or a series of XPath queries applied, so that
I can display a list of the <unit>, <sections>, and <areas> elements where
either the <paragraph> or <bullet> elements contain my search phrase. The
reason for this is that I have a "display_unit.aspx" page that parses via
XSL the <sections> or <areas> of the <unit> depending on what arguments are
passed into the page.

I've generated a schema using VS, but am getting a "Duplicated declaration
'paragraph'" and/or a "Duplicated declaration 'bullet'" error when I try to
read the schema into the XmlDataDocument.DataSet. I was thinking that maybe
the problem was that I needed to load a schema to make the DataSet
understand the XML. But, before I can successfully do this, I think I will
have to manually rewrite the schema to use namespaces.

I'll try what you have recommended without reading the schema. How would I
bind a seperately declared DataSet to the XmlDataDocument?
 
Sorry, I included the XML, but not the VB code. Her it is now...

Dim xDoc as New XmlDataDocument
xDoc.LoadXml("<searchable_xml/>") 'this creates the root node I need to
contain the loading xml documents

Dim xDocT As New XmlDocument
Dim dir As New DirectoryInfo(Server.MapPath("~/xml")) 'a directory in my
ASP.NET application
Dim fil As FileInfo() = dir.GetFiles("*.xml")
Dim finfo As FileInfo
Dim en As System.Collections.IEnumerator

'next, I'll enumerate through all the XML documents contained in the
directory
en = fil.GetEnumerator()
While en.MoveNext
finfo = CType(en.Current, FileInfo)
xDocT.Load(finfo.FullName)
xDoc.DocumentElement.AppendChild(xDoc.ImportNode(xDocT.DocumentElement,
True))
End While

'the above successfully creates my integrated XML document within the
XmlDataDocument class

'now I need to successfully bind my Web Control to the
XmlDataDocument.DataSet and call DataBind()
'however, if I reference the XmlDataDocument.DataSet.Tables.Count, it shows
nothing in the DataSet
 
so the code below creates the xml that you mentioned earlier. and you wish
to get that xml into a dataset.
the problem is simple. xml <==> dataset follows a very strict xml structure.

play around with it. if i get a few mins i will play around with your code
see how i get on with it.

--

Regards,

Hermit Dave (D'way)
http://hdave.blogspot.com
 
Thanks, HD. I didn't check back into the group yesterday, but made great
progress nonetheless. You can email me if you would like how I managed to
solve this and/or would like the url to the working solution.
 
Back
Top