473,770 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
XslTransformati ons. 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 2463
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
XslTransformati ons. 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 XIncludingReade r
(I'm talking about XInclude.NET [1]).

And what for SQL logic - you can encapsulate it to a custom XmlResolver
and provide it to XIncludingReade r, 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!P LEASEtkachenko. com> wrote in message
news:Of******** *****@TK2MSFTNG P11.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
XslTransformati ons. 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 XIncludingReade r
(I'm talking about XInclude.NET [1]).

And what for SQL logic - you can encapsulate it to a custom XmlResolver
and provide it to XIncludingReade r, 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 XIncludingReade r, 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 XIncludingReade r and use such proprietary URIs in your
master XML document, say
<xi:include href="sql://blah.blah.some. your.data"/>
XIncludingReade r 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?nam e=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(s trConn);
SqlDataAdapter dtaHolder = new SqlDataAdapter( "Select * from LPS_HOLDER
where FIRST_NAME like '%cook%'",conn) ;
SqlDataAdapter dtaLocation = new SqlDataAdapter( "Select * from
LPS_LOCATION",c onn);
conn.Open();
DataSet dsHoldLoc = new DataSet("Holder Location");
dtaHolder.Fill( dsHoldLoc,"Hold ers");
dtaLocation.Fil l(dsHoldLoc, "Locations" );
conn.Close();

DataRelation drHoldLoc = dsHoldLoc.Relat ions.Add("HoldL ocs",
dsHoldLoc.Table s["Locations"].Columns["INITIAL_LOCATI ON_ID"],
dsHoldLoc.Table s["Holders"].Columns["INITIAL_LOCATI ON_ID"],false);
drHoldLoc.Neste d = true;

dsHoldLoc.Write Xml(strmOutput) ;
strmOutput.Flus h();
strmOutput.Clos e();

Stephen

"Keith Chadwick" <kc*******@leew ardsystems.com> wrote in message
news:ei******** ******@TK2MSFTN GP09.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
XslTransformati ons. 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************ ****@agilisysNO SPAM.co.uk> wrote in message
news:u5******** ******@TK2MSFTN GP11.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(s trConn);
SqlDataAdapter dtaHolder = new SqlDataAdapter( "Select * from LPS_HOLDER
where FIRST_NAME like '%cook%'",conn) ;
SqlDataAdapter dtaLocation = new SqlDataAdapter( "Select * from
LPS_LOCATION",c onn);
conn.Open();
DataSet dsHoldLoc = new DataSet("Holder Location");
dtaHolder.Fill( dsHoldLoc,"Hold ers");
dtaLocation.Fil l(dsHoldLoc, "Locations" );
conn.Close();

DataRelation drHoldLoc = dsHoldLoc.Relat ions.Add("HoldL ocs",
dsHoldLoc.Table s["Locations"].Columns["INITIAL_LOCATI ON_ID"],
dsHoldLoc.Table s["Holders"].Columns["INITIAL_LOCATI ON_ID"],false);
drHoldLoc.Neste d = true;

dsHoldLoc.Write Xml(strmOutput) ;
strmOutput.Flus h();
strmOutput.Clos e();

Stephen

"Keith Chadwick" <kc*******@leew ardsystems.com> wrote in message
news:ei******** ******@TK2MSFTN GP09.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
XslTransformati ons. 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
5644
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: XmlReader instance from another module (beyond my control)
2
3718
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 public inside the class)
1
11185
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
1498
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. hmm does anyone know ? David Price
1
1278
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 very much data, but the data which they return may change often. I have a class which manages all the database stuff and it should return an XPathDocument. As this class has a constructor with an XmlReader parameter, I thought this could work...
1
6005
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; When this url formed is run in IE, it returns an xml in the browser. Now I want to duplicate this functionality in my code (like invoking this url from within a function and getting the xml as output from the
18
3210
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 that I retrieve from my stored proc and display it in a web page formatted as I want. I have managed to get my xml to display as I wish if I manually run my stored proc in QA and copy the xml into notepad and save it as Test.xml. I reference my xsl...
3
9910
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 xmlns:bk="http://www.lucernepublishing.com"> <book> <title>Pride And Prejudice</title> </book>
6
1874
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 = xmlDocument.CreateNavigator() Dim nodes As XPathNodeIterator = navigator.Select(queryString) If nodes IsNot Nothing AndAlso nodes.Count 0 Then Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder While nodes.MoveNext()
0
9618
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10259
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.