473,394 Members | 1,875 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,394 software developers and data experts.

Using XML as a Database

MT
I have a gigantic XML file which has the following structure:
<root>
<header>
</header>
<entry index="1">asdf</entry>
<entry index="2">fdfsa</entry>
........

</root>

Now, I have a simple XSD defined that automatically generates a Dataset for
me. I use the MyDatabase.ReadXml method to read the xml into the Dataset. It
fills the correct DataTables and DataRows automatically. I think this is an
inefficient way of reading the XML.

Is there a way I can do a query into my file so I can just grab my entry
with index "x" instead of reading the entire document using ReadXML?

Thanks,
MT
Nov 12 '05 #1
8 4344
Use an Xpath query on the XmlDataDocument

in xsl you could do

<xsl:tempate select="//entry[@index=$theindex">
do something
</xsl:template>

You could pass theindex up with a param object on your transform.

Or in code assuming the xml is store in a
XmlDataDocument object or other object that supports selectSingleNode

dim entryValue as string
entryValue=myxmldatadocument.selectSingleNode("//entry[@index=" & thenode &
"]").text

the XmlDataDocument is really slow for transforamtions though so you might
want to use a different object.

Cheers
Keith
"MT" <no****@nospam.com> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
I have a gigantic XML file which has the following structure:
<root>
<header>
</header>
<entry index="1">asdf</entry>
<entry index="2">fdfsa</entry>
........

</root>

Now, I have a simple XSD defined that automatically generates a Dataset for me. I use the MyDatabase.ReadXml method to read the xml into the Dataset. It fills the correct DataTables and DataRows automatically. I think this is an inefficient way of reading the XML.

Is there a way I can do a query into my file so I can just grab my entry
with index "x" instead of reading the entire document using ReadXML?

Thanks,
MT

Nov 12 '05 #2
Hello!

You could use an forward-only cached Xml reader like the XPathDocument, and
then create an XPathNavigator object using the .CreateNavigator() on the
XPathDocument.

The XPathNavigator allows you to query the Xml using an XPath expression
(and the .Select() method on that class). If your Xml is very heavy, I'd
suggest implementing an XmlTextReader instead (I've processed Xml files over
45MB with no problems at all - it's very snappy).

Is this what you're looking for?

venlig hilsen / with regards
anders borum
--
Nov 12 '05 #3
MT wrote:
I have a gigantic XML file which has the following structure:
<root>
<header>
</header>
<entry index="1">asdf</entry>
<entry index="2">fdfsa</entry>
........

</root>

Now, I have a simple XSD defined that automatically generates a Dataset for
me. I use the MyDatabase.ReadXml method to read the xml into the Dataset. It
fills the correct DataTables and DataRows automatically. I think this is an
inefficient way of reading the XML.
A way inefficent in fact.
Is there a way I can do a query into my file so I can just grab my entry
with index "x" instead of reading the entire document using ReadXML?


Just read document using XmlTextReader:

XmlTextReader r = new XmlTextReader("foo.xml");
while (r.Read()) {
if (r.NodeType == XmlNodeType.Element &&
r.Name == "entry" && r.GetAttribute("index")=="2")
Console.WriteLine("Entry value: {0}", r.ReadString());
}

That's the most effective way (and simple too).
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #4
Keith Chadwick wrote:
Use an Xpath query on the XmlDataDocument

dim entryValue as string
entryValue=myxmldatadocument.selectSingleNode("//entry[@index=" & thenode &
"]").text


Beware that's going to be extremelly slow. XmlDataDocument, big XML and
XPath with those // - the worst combination ever.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #5
Anders Borum wrote:
You could use an forward-only cached Xml reader like the XPathDocument, and
then create an XPathNavigator object using the .CreateNavigator() on the
XPathDocument.


XPathDocument is not forward-only cached Xml reader! XPathDocument loads
the whole document into memory to be able to navigate it in all
directions. It's more lightweight and faster than XmlDocument, but
anyway. If the querying logic is simple, just like in this case, ordinar
XmlReader is the best solution.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #6
Hi Oleg!

Sorry about the confusion witht the "forward only" statement. What I was
referring to was, that it's optimized for XPath queries (I was in a
different state of mind when I wrote that, I guess ..).

As long as we can agree that the XPathDocument is faster than the
XmlDocument for XPath queries in a read-only mode.

--
venlig hilsen / with regards
anders borum
--
Nov 12 '05 #7
Anders Borum wrote:
As long as we can agree that the XPathDocument is faster than the
XmlDocument for XPath queries in a read-only mode.


Sure! And apart from its speed - it takes much less space in memory due
to much simpler data model.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #8
MT
What about using the SQLXMLAdapter? Here's some information on it:
http://msdn.microsoft.com/library/de...us/sqlxml3/htm
/dotnet_0jck.asp

I will be sequentially reading the data from the XML file and I do need to
read it into the dataset. Wouldn't this be much easier?

MT
"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:u6**************@TK2MSFTNGP12.phx.gbl...
Anders Borum wrote:
As long as we can agree that the XPathDocument is faster than the
XmlDocument for XPath queries in a read-only mode.


Sure! And apart from its speed - it takes much less space in memory due
to much simpler data model.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #9

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

Similar topics

3
by: James | last post by:
HI, I'm looking for a script that will allow users/admins to have a one click backup solution for a MYSQL Database.. 'BACK DATABASE' button, click and its done... The a restore option, that...
2
by: cocoalearner | last post by:
I am serving a website using apache. All the php and mysql code I have written works, except for one thing. When I try to create a database named M#2 using the following call, no database is...
4
by: Nanchil | last post by:
Hi, We created a database (DB2 UDB 7.2 on solaris 8) without this (COLLATE USING IDENTITY ) option. But we need this now for binary sorting. The database is siebel database. Is it possible to drop...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
4
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
5
by: garyusenet | last post by:
At least I think it's using an API (i don't totally understand the concept.) I'm using Act 6. I need to interface with the act database and add 'contacts' to the database. The reason I need to...
10
by: Robert | last post by:
How do you get an accurate count of the number of records returned from a query when using linked tables. I have an access 2003 database as a front end to another access 2003 database that...
0
by: wingtong | last post by:
Our Deltek accounting software will be migrating from a Jet database to a SQL express database. In the past, when using the Jet database, I have been able to make a copy of the JET database to my...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
MrMancunian
by: MrMancunian | last post by:
How to create a database connection without using wizards Introduction I've seen a lot of questions on the net about getting data from, and saving data to databases. Here's a little insight how...
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:
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
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?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.