By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,180 Members | 1,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,180 IT Pros & Developers. It's quick & easy.

writing an xml inside XmlReader or XPathDocument to a file.xml

P: n/a
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)

Operations:

XPathDocument = new XPathDocument(XmlReader);

Then translation using XslTransform and output into

XML2.xml

NOW THIS IS WHAT I WANT TO DO:

How can I ALSO write the Incoming XmlReader to a file ?
I need this to help debug issues with the incoming file.

So in essence I want to be able to take an XmlReader or
XPathDocument and write it (without changing) to a .xml
file.

Ideas ? ( I know this one should be easy but I can think
at the moment and Type conversions dont seem to be
working )
Nov 11 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Figured it out. :D

Using LoadXML and WriteTo / Save Methods to read from
XmlReader and write to XmlWriter.

Pretty elementary. I dont know what I was doing.

-----Original Message-----
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)

Operations:

XPathDocument = new XPathDocument(XmlReader);

Then translation using XslTransform and output into

XML2.xml

NOW THIS IS WHAT I WANT TO DO:

How can I ALSO write the Incoming XmlReader to a file ?
I need this to help debug issues with the incoming file.

So in essence I want to be able to take an XmlReader or
XPathDocument and write it (without changing) to a .xml
file.

Ideas ? ( I know this one should be easy but I can think
at the moment and Type conversions dont seem to be
working )
.

Nov 11 '05 #2

P: n/a
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)
XPathDocument XpDoc;
XmlReader XrDoc;

- Constructor Render
public Render(XmlReader CleanXmlDoc,string SeriesXSL)

- It Loads 2 things:
the XML
the XSL

these objects are used by the following Methods using
Xsl.Transform method and other stuff

Methods:

public string RenderSectionPreview()
public string RenderHTML(String RenderMode)
public string RenderPDF(String RenderMode)

I was using
XPathDocument XpDoc = new XPathDocument(XmlReader);
inside the constructor and XpDoc was used as source for
XSLT translations in RenderHTML and RenderPDF.

Everything was working fine.

Now I decided to add 2 more methods to allow us to use the
same RenderObject (our custom class) and UPDATE the XML by
using the following Method ReloadXML.

Also wanted to add a WriteXML object that would allow us
to write the incoming XMLReader (for debug as well as
saving it)

New Methods:

public int ReloadXML(XmlReader CleanXmlDoc1)
public int WriteXML(String RenderMode)

The problem is in this process we are calling the

XPathDocument XpDoc = new XPathDocument(XmlReader);

with CleanXmlDoc1 (the new XML)

again.

We were hoping that the XpDoc would get populated with it
and we could use the XpDoc again as before in the
Xsl.Transform()

ANALYSIS:

After a lot of head breaking have come to the conclusion
that this has something to do with XPathDocument or
XmlReader and the current position of the cursor etc. or
something like that ? BUT I MAY BE COMPLETELY WRONG.
Is it something like this ? What is the issue ?

I tried using MemoryStream to store the XmlReader and then
use XPathDocument but logically I am still not able to re-
populate the XPathDocument XpDoc with a new XmlReader.

Kindly advise. Thanks.

-----Original Message-----
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)

Operations:

XPathDocument = new XPathDocument(XmlReader);

Then translation using XslTransform and output into

XML2.xml

NOW THIS IS WHAT I WANT TO DO:

How can I ALSO write the Incoming XmlReader to a file ?
I need this to help debug issues with the incoming file.

So in essence I want to be able to take an XmlReader or
XPathDocument and write it (without changing) to a .xml
file.

Ideas ? ( I know this one should be easy but I can think
at the moment and Type conversions dont seem to be
working )
.

Nov 11 '05 #3

P: n/a
xmlguy wrote:
I need to be able to re-use XmlReader and XPathDocument
for an XSLT Transform.


XmlReader cannot be reused. XPathDocument once it finished loading XML
is more than reusable - it's readonly.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4

P: n/a
I know that XPathDocument is read-only.

Question is..

Can I re-assign it to point to a "new" XPathDocument ?

for e.g.

XPathDocument XpDoc = new XPathDocument(XmlReader1);

...do stuff.. then..

XPathDocument XpDoc = new XPathDocument(XmlReader2);

is that not possible ?

If that is then can I do this ?
Call..
XPathDocument XpDoc = new XPathDocument(XmlReader1);
and then call it again later with the same XmlReader1 ??
XPathDocument XpDoc = new XPathDocument(XmlReader1);

Because when I do this somehow in the second assignment it
comes out as Null ? So is it because I have to re-
initialize XmlReader to Start ?

Hmm.. I am not sure what I am doing wrong ?

Is it better that instead of using XPathDocument I might
as well use XmlDocument ?? To avoid all this hassle ?

-----Original Message-----
xmlguy wrote:
I need to be able to re-use XmlReader and XPathDocument
for an XSLT Transform.
XmlReader cannot be reused. XPathDocument once it

finished loading XMLis more than reusable - it's readonly.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

.

Nov 11 '05 #5

P: n/a
xmlguy wrote:
Can I re-assign it to point to a "new" XPathDocument ?

for e.g.

XPathDocument XpDoc = new XPathDocument(XmlReader1);

..do stuff.. then..

XPathDocument XpDoc = new XPathDocument(XmlReader2);

is that not possible ?
Sure that's possible, just make sure you are not reusing XmlReader.
If that is then can I do this ?
Call..
XPathDocument XpDoc = new XPathDocument(XmlReader1);
and then call it again later with the same XmlReader1 ??


Nope. Again - you caanot reuse XmlReader. You have to create new one
every tim eyou need XmlReader.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.