473,614 Members | 2,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ExecuteXml Reader

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 2021
"Joe Gass" <jo*****@online .nospam> wrote in message news:uN******** ******@tk2msftn gp13.phx.gbl...
xr = oCom.ExecuteXml Reader : : 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 ExecuteXmlReade r using ReadNode( ). Something like
the following (untested) code,

' Set-up
Dim root As XmlElement
root = xmlDoc.CreateEl ement( "root")
xmlDoc.AppendCh ild( root)
xr.MoveToConten t( )

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

: :
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 ExecuteXmlReade r using ReadNode( ). Something like
the following (untested) code,

' Set-up
Dim root As XmlElement
root = xmlDoc.CreateEl ement( "root")
xmlDoc.AppendCh ild( root)
xr.MoveToConten t( )

' Repeat for each node until XmlReader is exhausted
Dim node As XmlNode
node = xmlDoc.ReadNode ( xr)
root.AppendChil d( 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("<lis tings>")
Do While xr.Read
sb.Append(xr.Re adOuterXml)
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
1785
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 home. The database schema for this order has about 15 related tables therefore I need to also have 15 related biz classes (for my brokers, appraisals, repairs, offers yada yada yada). The database schema may change slightly from week to week with...
0
1563
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 data into a single table using SQLXML/BulkXMLLoad. I have triggers set on an insert of this table to cascade inserts to the appropriate myriad of other tables. Originally I tried to use simpleType, then I tried to use: complexType, mixed="true"...
2
6837
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 the SYSTEM identifiers has no purpose in my application.) Anyway, when I load each document, using XmlDocument.Load(file), I get a FileNotFoundException, because of the DTD pointer in the SYSTEM identifier. I'd rather skip all the entity...
7
2739
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 ADODB.Recordset Dim oStream as New ADODB.Stream
3
6234
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 - <?xml version="1.0" ?>
2
2589
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 perfectly on my local test machine (it has VS 2005, SQL Server 2005 Ent, SQLXML 4.0 Libs and standard XP SP2 IIS) also for reference the same code works perfectly on a basic one page aspx file (with code behind). However when this web service or...
4
10541
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 SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class objBL = new SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class(); objBL.ConnectionString = "Provider=SQLOLEDB;server=cwp01004s;database=TestBulkLoad;uid=amjad;pwd=mirror;Trust_Connection=True";
2
9390
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
4473
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 with the xmlTextWriter, but I don't want to write to a file. But using methods like WriteStartElement, WriteAttributeString is very handy. Of course I can build the string with the stringbuilder but this is not a
0
8197
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
8589
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
8287
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
8443
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
7114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5548
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
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4136
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2573
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

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.