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

From n xmlReader to single XPathDocument?

My problem is this. I have to create several xmlReader objects each
retrieving 'for xml' formatted sql server data. I then need to peice them
together into a single document and place them into a single XPathDocument
which is then transformed throughout the web site with different
XslTransformations. I realize that the Xpathdocument will accept a
XmlReader as an object but I have 5 of them so how to 'best' combine. The
resulting XpathDocument is placed into the Cache and is only updated twice a
day.

Cheers
Keith

Note: I do note have access to the SQLXML objects on the production ISP site
otherwise I would use them!
Nov 12 '05 #1
8 2422
Keith Chadwick wrote:
My problem is this. I have to create several xmlReader objects each
retrieving 'for xml' formatted sql server data. I then need to peice them
together into a single document and place them into a single XPathDocument
which is then transformed throughout the web site with different
XslTransformations. I realize that the Xpathdocument will accept a
XmlReader as an object but I have 5 of them so how to 'best' combine.


You can create custom XmlReader, which reads all 5 other XmlReaders. See
"Customized XML Reader Creation" chapter in .NET Framework Developer's
Guide at
http://msdn.microsoft.com/library/de...ercreation.asp.

A more generic approach is XInclude. You can have one master XML, e.g.
<document xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="chapter1.xml" />
<xi:include href="chapter2.xml" />
<xi:include href="chapter3.xml" />
</document>
and then just read this document to XPathDocument via XIncludingReader
(I'm talking about XInclude.NET [1]).

And what for SQL logic - you can encapsulate it to a custom XmlResolver
and provide it to XIncludingReader, then having master document like

<document xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="sql://yoursqldata" />
<xi:include href="sql://yoursqldata" />
<xi:include href="sql://yoursqldata" />
</document>

[1] http://workspaces.gotdotnet.com/xinclude
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #2
Thanks Oleg,

I will read through and give it a try. The first example at MSDN is not
really worth it for what I have, seems like an awful lot of work for
something that should be relatively simple!

I am looking into the XInclude which I have downloaded.

Worst case scenario is I can load the sql/xml data and write it to file then
tell the XPathDocument to simply load it. In MSXML4.0 it was real easy,
guess I was expecting it to be as easy again. I am still struggling with
the objects under xsl/xml etc and how they work together. I find the
documentation somewhat lacking to say the least and the books I have only
cover very basic scenarios, of course!

By the way your suggestion to use the XPathDocument for my transformations
has greatly improved performance. I just ran an application test with 50
000 hits and had no problems what so ever, stratvucha, have no idea how to
spell thank you in russion only how to say it :-)

Cheers
Keith

"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:Of*************@TK2MSFTNGP11.phx.gbl...
Keith Chadwick wrote:
My problem is this. I have to create several xmlReader objects each
retrieving 'for xml' formatted sql server data. I then need to peice them together into a single document and place them into a single XPathDocument which is then transformed throughout the web site with different
XslTransformations. I realize that the Xpathdocument will accept a
XmlReader as an object but I have 5 of them so how to 'best' combine.
You can create custom XmlReader, which reads all 5 other XmlReaders. See
"Customized XML Reader Creation" chapter in .NET Framework Developer's
Guide at

http://msdn.microsoft.com/library/de...ercreation.asp.
A more generic approach is XInclude. You can have one master XML, e.g.
<document xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="chapter1.xml" />
<xi:include href="chapter2.xml" />
<xi:include href="chapter3.xml" />
</document>
and then just read this document to XPathDocument via XIncludingReader
(I'm talking about XInclude.NET [1]).

And what for SQL logic - you can encapsulate it to a custom XmlResolver
and provide it to XIncludingReader, then having master document like

<document xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="sql://yoursqldata" />
<xi:include href="sql://yoursqldata" />
<xi:include href="sql://yoursqldata" />
</document>

[1] http://workspaces.gotdotnet.com/xinclude
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #3
> And what for SQL logic - you can encapsulate it to a custom XmlResolver
and provide it to XIncludingReader, then having master document like

<document xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="sql://yoursqldata" />
<xi:include href="sql://yoursqldata" />
<xi:include href="sql://yoursqldata" />
</document>


Ok Oleg you wanna explain the above a little. I have the XInclude now but
could you provide an example of the magic that occurs with
"sql://yoursqldata". I hate black boxes and honestly do NOT understand the
hidden magic here.

Humbly
Keith
Nov 12 '05 #4
Keith Chadwick wrote:
By the way your suggestion to use the XPathDocument for my transformations
has greatly improved performance. I just ran an application test with 50
000 hits and had no problems what so ever, stratvucha, have no idea how to
spell thank you in russion only how to say it :-)


Credits due to XPathDocument developers at Microsoft, who created such
greatly effective and innovative component.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #5
Keith Chadwick wrote:
Ok Oleg you wanna explain the above a little. I have the XInclude now but
could you provide an example of the magic that occurs with
"sql://yoursqldata". I hate black boxes and honestly do NOT understand the
hidden magic here.


Well, sorry Keith, it was only an idea. This is not implemented in the
XInclude.NET yet, but sure will be in the next release.

The idea is based on custom XmlResolver technique, widely used in Java
world (it's called URIResolver in JAXP). First you implement custom
XmlResolver, which understands some proprietary URI schema, say sql://,
register it in XIncludingReader and use such proprietary URIs in your
master XML document, say
<xi:include href="sql://blah.blah.some.your.data"/>
XIncludingReader will call your XmlResolver to resolve the URI in href
attribute.
So in the custom XmlResolver code whenever you've been asked to resolve
such URI, you make you sql/xml logic and return result as XmlReader object.
That's it. I've heard one very smart guy is preparing an article about
using custom XmlResolvers, so watch MSDN news.

Meanwhile you can try merging via temporary files.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #6
Oleg Tkachenko wrote:
Meanwhile you can try merging via temporary files.

Alternatively create some aspx page, which returns generated XML and
call it in master document:
<doc xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="http://www.contoso.com/genxml.aspx?name=foobar"/>
</doc>
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #7
Keith,

Far be it for me to provide an alternative to the industrious Oleg,
[Excellent contributions both here and on his weblog]

If you're not too concerned about performance and are trying to build a
hierarchical XML representation of some obvious SQL relationships it may be
easier to build 5 data adaptors, create the relationships and then extract
the XML.

By test code looks like...

Database connection string in strConn
Streamwriter in strmOutput
SqlConnection conn = new SqlConnection(strConn);
SqlDataAdapter dtaHolder = new SqlDataAdapter("Select * from LPS_HOLDER
where FIRST_NAME like '%cook%'",conn);
SqlDataAdapter dtaLocation = new SqlDataAdapter("Select * from
LPS_LOCATION",conn);
conn.Open();
DataSet dsHoldLoc = new DataSet("HolderLocation");
dtaHolder.Fill(dsHoldLoc,"Holders");
dtaLocation.Fill(dsHoldLoc, "Locations");
conn.Close();

DataRelation drHoldLoc = dsHoldLoc.Relations.Add("HoldLocs",
dsHoldLoc.Tables["Locations"].Columns["INITIAL_LOCATION_ID"],
dsHoldLoc.Tables["Holders"].Columns["INITIAL_LOCATION_ID"],false);
drHoldLoc.Nested = true;

dsHoldLoc.WriteXml(strmOutput);
strmOutput.Flush();
strmOutput.Close();

Stephen

"Keith Chadwick" <kc*******@leewardsystems.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
My problem is this. I have to create several xmlReader objects each
retrieving 'for xml' formatted sql server data. I then need to peice them
together into a single document and place them into a single XPathDocument
which is then transformed throughout the web site with different
XslTransformations. I realize that the Xpathdocument will accept a
XmlReader as an object but I have 5 of them so how to 'best' combine. The
resulting XpathDocument is placed into the Cache and is only updated twice a day.

Cheers
Keith

Note: I do note have access to the SQLXML objects on the production ISP site otherwise I would use them!

Nov 12 '05 #8
This is basicaly what I did, but with datasets. 5 datasets merged into one
then pulled out as string which is then placed in an xmldocument which is in
turn placed in a xmlNodeReader which is then placed into the xpathdocument.
Works very well and although it might not be the most efficient means of
doing it, the resulting xpathdocument is placed in the cache and expires
each day at midnight. so efficinecy was is not my primary concern The
process only occurs once a day.

Cheers
Keith

"Stephen Cook" <st****************@agilisysNOSPAM.co.uk> wrote in message
news:u5**************@TK2MSFTNGP11.phx.gbl...
Keith,

Far be it for me to provide an alternative to the industrious Oleg,
[Excellent contributions both here and on his weblog]

If you're not too concerned about performance and are trying to build a
hierarchical XML representation of some obvious SQL relationships it may be easier to build 5 data adaptors, create the relationships and then extract
the XML.

By test code looks like...

Database connection string in strConn
Streamwriter in strmOutput
SqlConnection conn = new SqlConnection(strConn);
SqlDataAdapter dtaHolder = new SqlDataAdapter("Select * from LPS_HOLDER
where FIRST_NAME like '%cook%'",conn);
SqlDataAdapter dtaLocation = new SqlDataAdapter("Select * from
LPS_LOCATION",conn);
conn.Open();
DataSet dsHoldLoc = new DataSet("HolderLocation");
dtaHolder.Fill(dsHoldLoc,"Holders");
dtaLocation.Fill(dsHoldLoc, "Locations");
conn.Close();

DataRelation drHoldLoc = dsHoldLoc.Relations.Add("HoldLocs",
dsHoldLoc.Tables["Locations"].Columns["INITIAL_LOCATION_ID"],
dsHoldLoc.Tables["Holders"].Columns["INITIAL_LOCATION_ID"],false);
drHoldLoc.Nested = true;

dsHoldLoc.WriteXml(strmOutput);
strmOutput.Flush();
strmOutput.Close();

Stephen

"Keith Chadwick" <kc*******@leewardsystems.com> wrote in message
news:ei**************@TK2MSFTNGP09.phx.gbl...
My problem is this. I have to create several xmlReader objects each
retrieving 'for xml' formatted sql server data. I then need to peice them together into a single document and place them into a single XPathDocument which is then transformed throughout the web site with different
XslTransformations. I realize that the Xpathdocument will accept a
XmlReader as an object but I have 5 of them so how to 'best' combine. The resulting XpathDocument is placed into the Cache and is only updated
twice a
day.

Cheers
Keith

Note: I do note have access to the SQLXML objects on the production ISP

site
otherwise I would use them!


Nov 12 '05 #9

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

Similar topics

5
by: xmlguy | last post by:
I believe this should be pretty elementary, but for some reason I cannot seem to think of how to write the an XML file from an incoming XML file. Basically this is what I do: Input: ...
2
by: xmlguy | last post by:
Cant seem to solve this problem I need to be able to re-use XmlReader and XPathDocument for an XSLT Transform. Basically I have defined following interfaces: Class Render (Common and...
1
by: xmlguy | last post by:
PREVIOUS BACKGROUND POST: I am trying to reuse a Memory Stream for loading and transforming the xml it contains Basically I have defined following interfaces: Class Render {
1
by: david | last post by:
If I run the following code :- XmlReader rdr = dal.Getxxxx rdr.MoveToContent(); string xmlstring = rdr.ReadOuterXml(); how can I load the string back to a XPathDocument or a XPathNavigator....
1
by: Stampede | last post by:
Hi guys 'n' girls, I tried to obtain data from SQL Server by using the "FOR XML AUTO, ELEMENTS" clause and executing the SQLCommand with the ExecuteXmlReader() method. My queries will not return...
1
by: sudeeprgaitonde | last post by:
Hello, I am forming a aspx url with query string parameters as variables. sUrl = "http://abcd.com/getresults.aspx?zipcode=" + zipcode + "&areaCode=" + areacode + "&Landmark=" + landmark; ...
18
by: Terry Holland | last post by:
I have an asp.net (1.1) application that connects to a SQL server 2000 db. I have a stored procedure in my db that out puts data in xml format. What I need to be able to do is display that xml...
3
by: ano | last post by:
Hi, Anyone knows how to get "xmlns" value from XML file? For example, how to check that this xml file has a xmlns or not? Or how to read the xmlns value? <bookstore...
6
by: Kevin Burton | last post by:
I am come to rely on the following pattern to get the XML of a selected pattern with .NET 2.0 Dim xmlDocument As XPathDocument = New XPathDocument(xmlReader) Dim navigator As XPathNavigator =...
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: 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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.