473,406 Members | 2,894 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,406 software developers and data experts.

issues with repopulating XPathDocument with new XmlReader or XmlTextReader

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.

Nov 11 '05 #1
2 3696
If I understand everything correctly, then you problem is that you are
re-using the XmlReader that you attached to the MemoryStream.

An XmlReader is forward only, i.e. you cannot rewind it! You are on the
right track with using a MemoryStream though. You can rewind the
MemoryStream by setting Position = 0. Then you can attach a fresh
Xml(Text)Reader an re-read the stream.

Did I understand your problem and did this help?

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

"xmlguy" <xm****@yahoo.com> wrote in message
news:00****************************@phx.gbl...
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.

Nov 11 '05 #2
I believe you got me right.

Now the question is ..

Is there a better way than using a MemoryStream as
my "persistent" storage for the "current" Xml ?

Because I have two independent operations for that
persistent storage.

1. Use it against transforms (Xslt)
2. Re-populate it with new Xml from another source.

What would be the best Objects to use ?
Should I simply go with XmlDocument as the Storage.

Note: When I say "persistent" i mean for the "life and
scope" of that object ( the instane of my class Render )

Kindly do advise.

Thanks,

XmlGuy
-----Original Message-----
If I understand everything correctly, then you problem is that you arere-using the XmlReader that you attached to the MemoryStream.
An XmlReader is forward only, i.e. you cannot rewind it! You are on theright track with using a MemoryStream though. You can rewind theMemoryStream by setting Position = 0. Then you can attach a freshXml(Text)Reader an re-read the stream.

Did I understand your problem and did this help?

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

"xmlguy" <xm****@yahoo.com> wrote in message
news:00****************************@phx.gbl...
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.

.

Nov 11 '05 #3

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

Similar topics

3
by: CGuy | last post by:
Hi, I am using an XmlTextReader to read an xml file. It may happen that the file is present in the disk, but it may be empty (0 bytes). I would like to find out whether the xml file contains a...
5
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: ...
8
by: Keith Chadwick | last post by:
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...
4
by: Tomas Rivas | last post by:
I am trying to validate an xml file and schema and when I am trying to validate I am getting the following error. I have been trying to come out with a solution but I have failed so far. The...
1
by: Logician | last post by:
Task: To Read an XML document and handle data contents in .NET for new processing Request: Any details on how to read an XML document processing all nodes and content in .NET Problems:...
4
by: Sean Hoffman | last post by:
Framework 1.1 SP1. Page.xml is about 1.5mg. m_oXSLTransform.Transform takes about 2 minutes. When Page.xml is trimmed down to a smaller doc, it takes about 2 seconds. Same code ran in about...
0
by: Joe Pannone | last post by:
I need a way to allow a variable to equal an xml document. When using xpathdocument the parameter is asking for a filename. Since I plan on doing a lot of search in the xml document I would like...
2
by: jonfroehlich | last post by:
According to the MSDN documentation within the XmlTextReader class for ..NET 2.0, the recommended practice to create XmlReader instances is using the XmlReaderSettings class and the...
1
by: dignan.tenenbaum | last post by:
Hello, I'm using the XmlReader.ReadOuterXml() method to return the string representation of an xml node. The XmlReader is created with a file path and a XmlReaderSettings object. This was...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.