473,387 Members | 1,493 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.

load fragment into xmldocument without sqlxml

Hi
I have a query that uses for xml auto
I'd like to load this into an xmldocument with an xmlreader
e.g.
Dim xr As XmlReader
xmlDoc = New XmlDocument
xr = oCom.ExecuteXmlReader

If xr.Read Then
xmlDoc.Load(xr)
End If

This fails as there is not root node.
I've seen that a SqlXmlCommand can be use to specify a root to a fragment
Is there another way to do this without the need of sqlxml?
Cheers
Nov 12 '05 #1
2 2008
"Joe Gass" <jo*****@online.nospam> wrote in message news:uN**************@tk2msftngp13.phx.gbl...
xr = oCom.ExecuteXmlReader : : This fails as there is not root node.
I've seen that a SqlXmlCommand can be use to specify a root to a fragment
Is there another way to do this without the need of sqlxml?


Joe,

Create a document element in the XmlDocument manually to act as the
root. Then append child nodes to it that you get from the XmlReader
returned from ExecuteXmlReader using ReadNode( ). Something like
the following (untested) code,

' Set-up
Dim root As XmlElement
root = xmlDoc.CreateElement( "root")
xmlDoc.AppendChild( root)
xr.MoveToContent( )

' Repeat for each node until XmlReader is exhausted
Dim node As XmlNode
node = xmlDoc.ReadNode( xr)
root.AppendChild( node)
Derek Harmon
Nov 12 '05 #2
"Derek Harmon" <lo*******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
"Joe Gass" <jo*****@online.nospam> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
xr = oCom.ExecuteXmlReader

: :
This fails as there is not root node.
I've seen that a SqlXmlCommand can be use to specify a root to a fragment
Is there another way to do this without the need of sqlxml?


Joe,

Create a document element in the XmlDocument manually to act as the
root. Then append child nodes to it that you get from the XmlReader
returned from ExecuteXmlReader using ReadNode( ). Something like
the following (untested) code,

' Set-up
Dim root As XmlElement
root = xmlDoc.CreateElement( "root")
xmlDoc.AppendChild( root)
xr.MoveToContent( )

' Repeat for each node until XmlReader is exhausted
Dim node As XmlNode
node = xmlDoc.ReadNode( xr)
root.AppendChild( node)
Derek Harmon


Thanks Derek

Works a treat, I found a work-around but resulting xml wasn't quite as
expected
sb = New StringBuilder
sb.Append("<listings>")
Do While xr.Read
sb.Append(xr.ReadOuterXml)
Loop
sb.Append("</listings>")

Your method works a treat, thanks for taking the time to answer me
Cheers
Nov 12 '05 #3

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

Similar topics

1
by: Mark Sisson | last post by:
Ok gurus, what would you do? I'm developing an app in C# and trying to use SqlXml but there seems to be a problem at every turn. I want to create a biz object that represents an order to sell a...
0
by: Paula DiTallo | last post by:
Hello Techies-- I am reading an XML document with many nested elements. Many of these elements go to such a variety of tables, that I am trying to simply the read of the document by dumping the...
2
by: Gustaf Liljegren | last post by:
I need to merge several XML files into one large. All of them has a DOCTYPE tag, but the SYSTEM identifier points to a DTD that doesn't exist. (I use the PUBLIC identifier with catalog files, so...
7
by: Mac | last post by:
Hi all I have a asp.net application which calls a web service via a wdsl file which retrieves an XML String. The XML String is from a adodb recordset saved as via a stream. Dim oRS as New...
3
by: Atara | last post by:
I use the following code to load xml file: Dim srcXml As String = pathDataFiles & "test.xml" Dim XmlDoc As New Xml.XmlDocument XmlDoc.Load(srcXml) If my xml file starts with the line - ...
2
by: Andy Hunt | last post by:
Hi, I am having a problem with SQLXML Bulk Load inside of a web service ( also inside of a basic aspx page). I have a WebMethod in a web service that makes a call to bulk load. This works...
4
by: amjad | last post by:
Hi i have dataset which i write as xml file like ds.WriteXmlSchema(XSDFilename); ds.WriteXml(XMLFilename,XmlWriteMode.IgnoreSchema); then i try to load that file into sql using below code...
2
by: Shimon Sim | last post by:
Hi I keep getting error : WriteStartDocument cannot be called on writers created with ConformanceLevel.Fragment. The code that I have is very simple. SimpleClass c = new SimpleClass();
2
by: =?Utf-8?B?Q29lbg==?= | last post by:
Hi, can anyone tell me 1) what is a easy way to build a xml fragment into a string. I don't what the fragment to be written to file, just in a string will be fine. I can build the xml fragment...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.