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

Trouble Reading XML string

Ron
I have a method that generates an string in XML format and passes it to be
processed. The string is in the following format:

<grandparent>
<parent>
<child1>text</child1>
<child2>text again</child2>
</parent>
<aunt>
<cousin1>text</cousin1>
<cousin2>text2</cousin2>
<cousin3>text4</cousin3>
</aunt>
</grandparent>

string xmlInput = <values above>
XPathDocument xpDoc = new XPathDocument(new StringReader(xmlInput));
XPathNavigator xpNav = xpDoc.CreateNavigator();

//move to root element <grandparent>
xpNav.MoveToRoot();
xpNav.MoveToFirstChild(); //move to <parent>
xpNav.MoveToFirstChild(); //move to <child1>
strChild1 = xpNav.Value;
xpNav.MoveToNext(); //move to <child2>
strChild2 = xpNav.Value;
.....

The problem I am having is that the xpNav.Value keeps concatenating every
other value onto itself. So instead of having:
strChild1 = "text";
and
strChild2 = "text again";
as I expect, I am getting the following:
strChild1 = "texttextagain";, etc.

Can anyone give me any ideas as to what I am doing wrong and how I might be
able to fix it?

Thanks for your help,

Ron


--
--------------------------------------------------------------
Ron Rodenberg
Lead Software Engineer
Razorvision Technology
8080 N. Central Expressway
Suite 400
Dallas, TX 75206
Nov 11 '05 #1
1 2441
Ron wrote:
I have a method that generates an string in XML format and passes it to be
processed. The string is in the following format:

<grandparent>
<parent>
<child1>text</child1>
<child2>text again</child2>
</parent>
<aunt>
<cousin1>text</cousin1>
<cousin2>text2</cousin2>
<cousin3>text4</cousin3>
</aunt>
</grandparent>

string xmlInput = <values above>
XPathDocument xpDoc = new XPathDocument(new StringReader(xmlInput));
XPathNavigator xpNav = xpDoc.CreateNavigator();

//move to root element <grandparent>
xpNav.MoveToRoot();
xpNav.MoveToFirstChild(); //move to <parent>


Nope. Move to <grandparent>. Reread what MoveToRoot() method does:
"Moves to the root node to which the current node belongs.

public abstract void MoveToRoot();

Remarks
All nodes belong to one and only one document. Therefore, this method is
always successful. For a definition of a root node, see section 5.1 of the W3C
XML Path Language (XPath) recommendation located at
http://www.w3.org/TR/xpath#data-model."

Root node in XPath data model is not grandparent element, it's its parent.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2

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

Similar topics

4
by: somaboy mx | last post by:
hi, I'm on winXPpro / apache 1.2 / php 4.4.x I'm experimenting with writing and reading from textfiles via php. I can create a file with fopen, write to it, but I'm having trouble reading...
3
by: Michael Harris | last post by:
Access XP WinXP Adobe Acrobat 5.0 I'm playing with Keri Hardwick's "Save a report's output as a PDF file" and most of it still works. The problem is the ChangePdfFileName is not changing the...
1
by: Andre Ranieri | last post by:
I'm having trouble programatically inserting an Excel file into an Image column in our CRM package's SQL 2000 database. The function appears to work ok, but when I attempt to access the file through...
1
by: Westbrook, Christopher L (WESTBCL04) | last post by:
I am having some trouble, and I can't figure out why. I'm trying to use the simple keylogger project from source forge, and then create a web interface to open the resulting files, so people from...
2
by: spidey12345 | last post by:
what i need this program to do is to read paragraphs like "st blah blh test ere se sit blha eere w" and then it will reformat to "st blah...
0
by: Anish G | last post by:
Hi, I have an issue with reading CSV files. I am to reading CSV file and putting it in a Datatable in C#. I am using a regular expression to read the values. Below is the code. Now, it reads...
7
by: shendraeg | last post by:
I'm trying to use fstreams to format/encode a text file in a way that is useful for another program of mine, and I came upon a little snag... The input file is formated as such: int (line count)...
3
by: angi35 | last post by:
I'm having a zero-length string problem... Hoping someone can help. (This is in Access 2000.) In FormA, I have a button that opens FormB with OpenArgs. In FormB, the OpenArgs are translated into...
3
by: Rune Allnor | last post by:
Hi all. I am trying to use std::stringstream to validate input from a file. The strategy is to read a line from the file into a std::string and feed this std::string to an object which breaks it...
5
by: javanianewbie | last post by:
Hello, I am having trouble when I read in a a file and parsing part of it as an int using substring. Here is the code I have: String input = ""; while(readFile.hasNextLine())
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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,...

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.