Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 27th, 2007, 05:21 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default XPATH removing nodes from file??

Hello everyone,
    This seems to be a somewhat odd problem that I am having so I hope someone can shed some light on the subject. I have a specialized XML file that implements XFDL (it is a source document for IBM's Workplace Forms) and it is structured much like that of a plain run of the mill XML document albeit its DTD defines alot of custom tags.

Here is my situation: These files are to be uploaded through a Webform and stored in an image column inside of SQL Server. This protion of the application works wonderfully, however, before I get to this step I have to open the file and grab a piece of data from a particular node.

Since this file doesn't exist on the file system, I am opening the file from the input stream such as this:

Code:
XmlTextReader xtr = new XmlTextReader(userPostedFile.InputStream);
XPathDocument xDoc = new XPathDocument(xtr);
XPathNavigator xNav = xDoc.CreateNavigator();
XPathNodeIterator xIter = xNav.Select("//PAGE1");
This works fine and I am able to load the entire file into the XPathDocument and the node that I need is a child of <PAGE1></PAGE1>

So I wrote a loop:
Code:
while (xIter.MoveNext())
{
//loop till we get to the node <ClientNo></ClientNo>
}
However, I never reached the ClientNo node so I setup a hook right before the begining of this loop to see how many times it executed and, to my suprise, it didn't execute at all.

I then added this directly before the loop to see what data my Iterator was holding:
Code:
Response.Clear();
Response.ContentType = "text/xml";
Response.Write(xIter.Current.ToString());
Response.End();
This errored on me when it went to display as IE said it was not a valid XML document, however just doing

Code:
Response.Write(xIter.Current.ToString());
Writes out the entire file to the screen void of all Tags.

A sample of the file looks like this:
Code:
<PAGE1>
<navigation></navigation>
<FormProviderAgency>CSS</FormProviderAgency>
<ClientName readonly="true">Artifical Client</ClientName>
<ClientNo>2006821</ClientNo>
<DateOfAdmission>20060330</DateOfAdmission>
<PresentingProblem>Test symptoms</PresentingProblem>
...
</PAGE1>
But it literally gets wrote out as:CSSArtifical Client200682120060330Test symptoms

Does anyone have any idea as to why all of the tags would be seemingly stripped away? Does it have to do with the fact that I am working with it as a Stream as opposed to opening a source document on the filesystem? (Though I am not sure why that would make any difference.)

Any help would be greatly appreciated.


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old February 27th, 2007, 05:37 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

>< Upon testing this a little farther, I created a text file and dumped all of the data into that text file and , upon opening the file, the data was persisted exactly as it appears in the source document?

I could turn around and use this file as the source document for my XPathDocument, however, I would like to handle everything in memory without writing a file down to the server.

Any thoughts?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429





Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing duplicate nodes post-process QuickSilver002 XSLT 3 April 4th, 2007 03:47 PM
How to use Xpath to extract child nodes smilysuresh XSLT 3 February 23rd, 2007 06:32 AM
Removing nodes with an XSLT Jza XSLT 2 April 19th, 2006 10:06 AM
XPath not finding nodes, need help Alderian72 XSLT 1 June 16th, 2005 10:49 AM
XPath - Selecting nodes based on attribute values billy_bob_the_3rd XML 4 December 1st, 2004 06:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.