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

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 )


0
xmlguy (13)
10/9/2003 9:52:20 PM
dotnet.xml 7266 articles. 0 followers. Follow

5 Replies
921 Views

Similar Articles

[PageSpeed] 58

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 )
>
>
>.
>
0
xmlguy (13)
10/9/2003 10:13:57 PM
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 )
>
>
>.
>
0
xmlguy (13)
10/10/2003 3:31:54 AM
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

0
oleg7603 (294)
10/10/2003 3:35:53 PM
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 XML 
>is more than reusable - it's readonly.
>-- 
>Oleg Tkachenko
>http://www.tkachenko.com/blog
>Multiconn Technologies, Israel
>
>.
>
0
xmlguy (13)
10/10/2003 6:47:02 PM
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

0
oleg7603 (294)
10/12/2003 5:36:31 PM
Reply:

Similar Artilces:

XML Custom serialization
Hi all, I want to serialize a class in a customized way. But I don't want to implement the ISerializable interafce because I don't want to take care of every new field I insert to the class. What I need is a way to customize the serialization of a specific field in my class but leave the rest to the build-in serialization. Any guidance will be appreciated. Ro'ee <sfa.roy@gmail.com> wrote in message news:7243a1eb-3fa3-43e0-8339-d90f890e6716@b1g2000hsg.googlegroups.com... > Hi all, > > I want to serialize a class in a customized way. But I don't want to >...

Macro Help- combining "CS" files
Below is the macro I have to go to a certain file and combine all spreadsheets. I did not write this macro myself. I just received it and modified it to work for my situation. When this maco is run it gets to the first file and says I cannot change a read only file and says I must unprotect the worksheet. This sheet is not protected but I really only want to copy the info on it anyway. Is there a way to modify this macro to copy the information. I could save all of the "CS" files as new files but that would defeat the purpose of automating this job Any help is greatly a...

Import data from DBF files
What's the best way to import a large dbf file into Access (records from a DBase file)? I have one dbf that has over 220,000 records in it. It gets to about 75% and says "The search key was not found in any record." Everything is patched to the max (Windows, Office, Jet, etc). This doesn't happen with any other dbf file, but they are all smaller. Also, oddly, I can copy and paste 50,000 records in a shot and paste them through a query, but I don't want to keep doing that for every large dbf I have. The Access tables have no problem holding the data, just transf...

Is there a way for Windows Service to Read/Write HKCU Reg key ?
Hi: I'm writing a Windows Service program which needs to read/write the HKEY_CURRENT_USER registry key for the current logged on user. I know that for a Windows service does not have concept of HKCU since it is always running in SYSTEM's context. But is there a way (trick?) for a service to access the HKCU registry key? Thanks In Advance ! Polaris Hello Try, from a user application (the one that is logged on, or the current user), to send the services the user's SID. Then access the HKCU through HKEY_USERS\users_sid\............ Hope that helps, Elias "Polaris&qu...

"File not found" and "The form name is misspelled..." errors
I am still bulding a database. It contains no data, and contains no embedded macros. Yet, when I go to build code, I get these errors: "File not found" followed by "The form name * is misspelled or refers to a form the doesn't exist" The problem does not lie in the form that automatically opens when the database opens, and there are no embedded macros (I've read that these are the two main places an error such as this can occur). I did a search in the code box, and do find the two subforms listed even though neither contains any kind of code. I ca...

Write
I am trying to change the default margins. I am requested to use the Write mode to do this. What is Write, and how do I access it? Are you using voice recognition? Margins are simply changed in the Arrange Menu in Publisher. Are you in the right newsgroup? -- Mary Sauer MS MVP http://office.microsoft.com/ http://www.mvps.org/msauer/ news://msnews.microsoft.com "CBC" <anonymous@discussions.microsoft.com> wrote in message news:183bb01c44a40$107bd5d0$a501280a@phx.gbl... > I am trying to change the default margins. I am requested > to use the Write mode to do this. W...

pst files and VPN issues
I'm looking for suggestions on how to configure .pst files for remote users who access a network using VPN. Due to the large size of these files (often over a gigabyte), Outlook's performance is seriously affected and often freezes during the archive process. What are your company's polices for remote users accessing .pst files and is there a way short of saving them locally to access them without affecting Outlook's performance? If the .pst has to be stored and backed up locally, does anyone have security advice for protecting .pst files with sensitive material? Encrypted f...

insert .dxf files
Hi, Anyone knows how to insert .dxf files into power pt 2003. i'm able to do it on power pt '97. or perhaps point to where i can add the filters in thks in advance :) -- it''''s not the eye that is blind, blind is the eye within the bossom In article <3CBADB93-1D61-47A1-90AB-9DDA49A5C42A@microsoft.com>, Ssa wrote: > Hi, > Anyone knows how to insert .dxf files into power pt 2003. i'm able to do it > on power pt '97. or perhaps point to where i can add the filters in Normally, Office's graphics filters are stored in: C:\Pr...

adding animated swf file as background.
hi. I am developing a s/w in VC++. it is loaded with heavy UI. now my client want me add a animated flash file(swf file) as a back ground. if any body knows how to do it, please tell me. thanx in advance. Regards, Harshad. ...

SHRINK/REDUCE EXCEL FILE SIZE
Hi Friends, A useful post on reducing the excel workbook size. This may reduce the file size dependently from 10% to 500% . http://www.excelitems.com/2010/11/shrink-reduce-excel-file-size.html ________________________________________ Thanks & Regards Ashish Jain (Microsoft Certified Application Specialist) (Microsoft Certified Professional) http://www.excelitems.com http://www.openexcel.com ________________________________________ ...

CSV to XML, now to validate
hiya, I have a 3rd party function that converts a CSV to an XML doc. I now need to validate the xmlDoc.I understand that I need a valid XSD for the newly created xmlDoc, but the xmlDoc contains no schema definitions etc.I'm not sure how to create an XSD, so that the fields are restricted to "integer" datatypes etc. Been looking for a while.I assume that I don't have to manually write an XSD?maybe I should create a "dummy" table in sqlServer, then generate a dataset to get the XSD?Or, maybe vis studio 2003 has tools to make this easier? Any suggestions appreciated...

Writing formula for excel worksheet
Item Rate1 Rate2 Rate3 A 3 4 6 B 8 5 23 C 56 5 78 Above is my excel sheet. I want to write some formula so that in every row cell having minimum rate should come bold. Like For Item A - Rate1(3) for Item B - Rate2(5) For Item C - Rate2 (5) There may be a neater way but this works. Somewhere in you sheet in a cell type =min(A1:a4), I used L1 Change this to watever range you are trying to evaluate. Then select this range and click format - conditional format - cell value - is equal to =($L$1) and apply your bold font. The lowest value in the range will then become bold. Mike "Gaur...

write protect/write redirect/kios mode
Hey, I LOVE snapshots in virtualmachines and think it would be awesome to have something like this for my main windows install. Anyone know of any hardware/software to redirect writes to another drive/file/memory/hardware? Or hardware to write protect a drive for kios's (i found some once befor the reverted all changes on shutdown, but cant find it anymore ><) I know VSS(virtual shadow copy service) has a function to redirect on write and wondering if i might be able to use that :/ It will just make everything cleaner, and give alot of flexiblity to setting up ...

XSLT: Creating anchors from outer XML files
Hi, I'm trying to put the links (href attribute of the <a> element) out of my XSLT files, in a XML file, and read it from the stylesheet. I suppose that I have to use the document() function to link to the XML file containing the URLs, but I don't know how to do it. I've tried something like this: This is XML file containing the URLs (link.xml): <?xml version="1.0" encoding="utf-8" ?> <LINKS> <L1> /SomePage.aspx </L1> </LINKS> And this is the code from the stylesheet: <a href="{document('link.xml')/L...

How to get the sectors/clusters of a particular file?
Hi, How to get the sectors/clusters of a particular file? I am working on Windows 2000. Hoping to get a reply soon. TIA. regards, Jahfer V P. No particular way I know of. If you have certain privileges you might be able to use DeviceIoControl(), but there isn't much you can do with this information. joe On Mon, 20 Jun 2005 23:33:02 -0700, "Jahfer V P" <JahferVP@discussions.microsoft.com> wrote: >Hi, > >How to get the sectors/clusters of a particular file? >I am working on Windows 2000. > >Hoping to get a reply soon. >TIA. > >regards, &g...

How to replace two system files?
I have an XP machine. Have just replaced a couple files from a W7 machine. The files are:- c:\windows\system32\drivers\disk.sys c:\windows\system32\drivers\partmgr.sys ....and now I can't boot the XP machine. How to get back to before I replaced the files? Thanks. "John Smith" <JohnSmith@nospam.com> wrote in message news:uLL8mqL0KHA.264@TK2MSFTNGP05.phx.gbl... > I have an XP machine. Have just replaced a couple files from a W7 machine. > The files are:- > c:\windows\system32\drivers\disk.sys > c:\windows\system32\drivers\partmgr.sys > ....

Cannot open .msg files saved from Outlook to network share
Some of my users have dragged and dropped emails into their network shares creating .msg files. When they try to open some of the files they get the following popup: 'The messaging interface has generated an unknown error. If the problem persists, restart Outlook.' This only happens for some of the saved emails. They are using Outlook 2000 from Office. God only knows why they did this and didn't use autoarchive! How many training sessions does someone have to do?! Anyway, anyone know how I can open them or even better, why I cant? Regards Dave ...

Cannot write to memory location
I can not (all of the sudden) run Publisher in the last week. When starting to run it, I get that it cannot write to a certain memory locaiton, so it is shutting down. I need to get this program working. I have read through this forum and tried the different fixes as well as the knowledge base (emptied the temp file, disabled anti-virus, etc.) but it still won't work. An example is: "The instruction at "0x77f585c0" referenced memory at "0x00000000". the memory could not be "written". Click on OK to terminate the program." The header read...

deleting temp web files
When I delete the temporary internet files with the Iexplorer menu of Tools->InternetOptions->General->DeleteFiles Does this delete said files only for the current User account logged on? Or does it delete said files for all user accts on machine ? Just the current user I think. neil "RB" <NoMail@NoSpam> wrote in message news:#FNlBGX3KHA.1016@TK2MSFTNGP02.phx.gbl... > When I delete the temporary internet files with the Iexplorer menu of > Tools->InternetOptions->General->DeleteFiles > Does this delete said files only for the current...

how do i write checkbox to.....
This is a multi-part message in MIME format. --------------050607000103070200020407 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit how do i write checkbox1 boolean to xml in vb6 i can only do cstr( checkbox1.value) but in vb.net can't write to xml. i am doing irc chat similar to mirc or pirch chat. rw.WriteConfigInfo("User Modes", chkInvisible.Text, chkInvisible.Checked, "PirateChat.xml") in procedure events: ' Both the Key and the Value are filled ' Find the key ...

Finding and marking duplicate accounts inside CRM (solution)
It is quite easy to check duplication on excel sheet andI thought that i should share this solution with you guys.It deals with checking duplication and updating the duplication (bit field) to yes . Step 1 = Make a Boolean Field(e.g duplicate) on account form . Step 2 = Develop a .Net Assembly , which find and update existing duplicate accounts (this assembly only check duplicate name) public class Bulkupdate { public void Bulking(string Navn ) { try { CrmService service = new CrmService(); service.Credentials = System.Net.CredentialCache.DefaultCredentials; ...

xml to flat file
Hi. Is there any way of using an xml schema file to a. validate the xml data then writing the xml out as a flat flat. For example in the schema it would say the element has a maximum length of 10 characters and therefore when it is written out as text the value is 10 characters ? <field1>hello</field1> <field2>all</field2> flat file would be hello_____all thanks ...

Extend the XML Schema via C# objects
I have C# objects/entities (like person or customer) which contains the usual amount properties/attributes like name, address and so on.. I would like to "tag" some of these properties, so that when I'm generating and XML Schema (via Wsdl for instance) the tags are displayed in the Schema portion of the Wsdl. Something like the following snippet: <?xml version="1.0" encoding="utf-8"?> <xs:scheme attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" ...

How to Insert Excel file into webpage
Hi I have made some tax calculators and would like to know how to insert them onto my website. I have tried the frontpage route but the user will have to download "Excel XP Web component" to be able to view it. Is there any other method where the web user be able to see/use the calculator without downloading any additional software for example like this website http://listentotaxman.com which I believe he made in "mysql" How can I achieve the same result by inserting my excel file in a website? Thanks ...

Hanging while Saving the Excel File
Hi, While when I try to Save My Excel File the system is Hanging . I had also Reinstalled the MSOffice but the Same problem exits.please Give me any solution to solve this. Hi Prabu, We need some more information. Does this problem exist for just one file or do you have problems for all Excel files? By "Hanging" do you mean freezing or just taking a long time? These answers might help someone find a solution. --- Message posted from http://www.ExcelForum.com/ ...