Read content of XmlReader ?

Read content of XmlReader ?

Post by Dennis Myré » Fri, 29 Nov 2002 21:31:04



Hi.
I am using an System.Xml.XmlReader class instance to retrieve XML data from
a SQL server,
by running a stored procedure located in the database.
Structure of output document:
<node>
    <child></child>
</node>
<node>
    <child></child>
</node>
<node>
    <child></child>
</node>

When using the XmlReader, i get only the first <node> element:

<node>
    <child></child>
</node>
<child></child>
<child></child>

I use this code:

XmlReader r = (XmlReader) com.ExecuteXmlReader();
r.MoveToContent();
while (r.Read())
{
    sb.Append(r.ReadOuterXml());

Quote:}

Anyone ?

Thank You
Regards
Dennis

 
 
 

Read content of XmlReader ?

Post by john farro » Sat, 30 Nov 2002 04:40:51


That output document is not valid XML, to be valid you must have only one
root level element, so the reader is probably starting and finishing the
first root level element and the assuming the document is finished.


Quote:> Hi.
> I am using an System.Xml.XmlReader class instance to retrieve XML data
from
> a SQL server,
> by running a stored procedure located in the database.
> Structure of output document:
> <node>
>     <child></child>
> </node>
> <node>
>     <child></child>
> </node>
> <node>
>     <child></child>
> </node>

> When using the XmlReader, i get only the first <node> element:

> <node>
>     <child></child>
> </node>
> <child></child>
> <child></child>

> I use this code:

> XmlReader r = (XmlReader) com.ExecuteXmlReader();
> r.MoveToContent();
> while (r.Read())
> {
>     sb.Append(r.ReadOuterXml());
> }

> Anyone ?

> Thank You
> Regards
> Dennis


 
 
 

Read content of XmlReader ?

Post by Chris Lovet » Mon, 02 Dec 2002 17:35:04


ReadOuterXml() is advancing to the next element already, so you are doing one
too many reads.  Try it this way:

while (! r.EOF) {
    sb.Append(r.ReadOuterXml());

}

> Hi.
> I am using an System.Xml.XmlReader class instance to retrieve XML data from
> a SQL server,
> by running a stored procedure located in the database.
> Structure of output document:
> <node>
>     <child></child>
> </node>
> <node>
>     <child></child>
> </node>
> <node>
>     <child></child>
> </node>

> When using the XmlReader, i get only the first <node> element:

> <node>
>     <child></child>
> </node>
> <child></child>
> <child></child>

> I use this code:

> XmlReader r = (XmlReader) com.ExecuteXmlReader();
> r.MoveToContent();
> while (r.Read())
> {
>     sb.Append(r.ReadOuterXml());
> }

> Anyone ?

> Thank You
> Regards
> Dennis

 
 
 

1. How to convert the content of XmlReader to String

Hi,
I am executing a raw xml query on SQL, my code looks like -

XmlReader reader = objSqlCommand..ExecuteXmlReader();

StringWriter objStringWriter = new StringWriter();
XmlTextWriter objTextWriter = new XmlTextWriter(objStringWriter);

while(!reader.EOF)
{
   reader.MoveToContent();
   objTextWriter.WriteNode( reader, false);

string temp = objStringWriter.ToString();

Can I optimize the code?
I want to close the connection to SQL after ExecuteXmlReader,
is there any alternate to achieve it in .NET?

Thanks in advance,
Venkatesh

2. realtime signal processing

3. XMLReader and large Element contents

4. Opportunity For Getting Back at AOS's

5. reading binary array with XMLReader

6. Differences between MS95 Win x86 versions

7. File content distorted after being read by scripting.filesystem

8. overloading inheritance

9. text file content comes out as garbage when read on PocketPC

10. read text content of an xml element in c#

11. Reading the contents of an MSM file

12. is it possible to read content of web page

13. Can one site read the directory contents of another site on same server?