473,769 Members | 8,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(XmlReade r CleanXmlDoc,str ing 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 RenderSectionPr eview()
public string RenderHTML(Stri ng RenderMode)
public string RenderPDF(Strin g RenderMode)

I was using
XPathDocument XpDoc = new XPathDocument(X mlReader);
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(XmlRe ader CleanXmlDoc1)
public int WriteXML(String RenderMode)

The problem is in this process we are calling the

XPathDocument XpDoc = new XPathDocument(X mlReader);

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 3717
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.c om> 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(XmlReade r CleanXmlDoc,str ing 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 RenderSectionPr eview()
public string RenderHTML(Stri ng RenderMode)
public string RenderPDF(Strin g RenderMode)

I was using
XPathDocument XpDoc = new XPathDocument(X mlReader);
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(XmlRe ader CleanXmlDoc1)
public int WriteXML(String RenderMode)

The problem is in this process we are calling the

XPathDocument XpDoc = new XPathDocument(X mlReader);

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)Reade r 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.c om> 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(XmlReade r CleanXmlDoc,str ing 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 RenderSectionPr eview()
public string RenderHTML(Stri ng RenderMode)
public string RenderPDF(Strin g RenderMode)

I was using
XPathDocument XpDoc = new XPathDocument(X mlReader);
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(XmlRe ader CleanXmlDoc1)
public int WriteXML(String RenderMode)

The problem is in this process we are calling the

XPathDocument XpDoc = new XPathDocument(X mlReader);

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
5424
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 valid root node or not. How do I do this? This is what I need if(File.Exists(fileName)) {
5
5644
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: XmlReader instance from another module (beyond my control)
8
2462
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 single XPathDocument which is then transformed throughout the web site with different XslTransformations. I realize that the Xpathdocument will accept a XmlReader as an object but I have 5 of them so how to 'best' combine. The resulting...
4
1907
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 document validates ok in xmlSpy but it fails in VS2003. Is there any article or fix for this? Thnaks in advance. Error: ======
1
1730
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: Duplicate DATA tags, end nodes (ley01) and then data lower down, system loses its positions My Experience: Handling XML/HTML via Transforms, writing XML using
4
1907
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 4 seconds under asp. not using <xsl:key>.
0
1058
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 to supply a variable instead of the xml doc. This is the code I use: dim docNav As XPathDocument docNav = New XPathDocument("c:\adsp_dispatch.xml") I would like to use something like:
2
6858
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 XmlReader.Create() method. However, the problem is, the XmlReader class does not expose certain properties that I need, e.g., LineNumber, LinePosition, etc. I would like to follow Microsoft's recommended practices, but I'm not sure how I can get XmlTextReader...
1
4388
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 working fine until a default namespace was introduced. When the default namespace is defined the ReadOuterXml() method began adding a bunch of extra namespace declarations to the string it returned. xml example ...
0
9589
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
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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...
0
8876
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
6675
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();...
1
3967
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
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.