473,785 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading xml nodes

Hello!

I am currently playing around with XmlTextReader and XmlTextWriter.
I've got the TextWriter to write out nodes in this form:

<node>
<childnode>more data</childnode>

<childnode>more data</childnode>

<childnode>more data</childnode>
</node>

What I'having trouble with, is to read these nodes using xmlTextReader.

In all the examples I've seen, the xml format has been different from the
format I've used:

<node someAttribute=" data" someOtherAtribu te="moredata">
<childnode someAttribute=" data" someOtherAtribu te="moredata"/>
<childnode someAttribute=" data" someOtherAtribu te="moredata"/>
</node>

So , I have 2 questions:
-Does anyone have an example on how to read the xmlformat I've used?
-Is this a correct / incorrect xml data format?

Also, If an attribute or a node's data contains " or ', will this mess up
the xmlReader?
Example: <childnode someAttribute=" She didn't do it">

Regards Christian H.

Nov 16 '05 #1
1 1898
How I would read this is:

Put the xml in an XmlDocument
Select all the childnodes using:

XmlNodelist nodeList = xmlDoc.SelectNo des("//node/childnode");
foreach(XmlNode xmlNode in nodeList)
{
// use xmlNode.InnerTe xt to get the moredata
}
And yes your xml data is correct.
Xml data can never contain " or ' as far as I know, you always need to use
special codes for that. For example, <node>A & B</node> is not valid, the
right notation would be <node>A &amp; B</node>
I'm sure the same goes for " and '

Good luck,

Razzie

"Christian H" <n@n.no> wrote in message
news:x4******** **********@news 4.e.nsc.no...
Hello!

I am currently playing around with XmlTextReader and XmlTextWriter.
I've got the TextWriter to write out nodes in this form:

<node>
<childnode>more data</childnode>

<childnode>more data</childnode>

<childnode>more data</childnode>
</node>

What I'having trouble with, is to read these nodes using xmlTextReader.

In all the examples I've seen, the xml format has been different from the
format I've used:

<node someAttribute=" data" someOtherAtribu te="moredata">
<childnode someAttribute=" data" someOtherAtribu te="moredata"/>
<childnode someAttribute=" data" someOtherAtribu te="moredata"/>
</node>

So , I have 2 questions:
-Does anyone have an example on how to read the xmlformat I've used?
-Is this a correct / incorrect xml data format?

Also, If an attribute or a node's data contains " or ', will this mess up
the xmlReader?
Example: <childnode someAttribute=" She didn't do it">

Regards Christian H.


Nov 16 '05 #2

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

Similar topics

3
4838
by: Dinesh_GR | last post by:
Hi all, I have many parent tags and many child tags under the respective parent.. in an XML file. On the click of a button the application should pick up the one parent and the corresponding child and bind it to a grid. Like that it goes on for the next parent and the related child for the next button click.
1
3807
by: Michael Søndergaard | last post by:
I am trying to read all orders element, which have the attribute Phase="Reorganize". I am using the following code on the xml document. private void LoadPhase (XmlDocument Doc, TreeNode Parent, Phase OrderPhase) { XmlNodeList Nodes = Doc.SelectNodes("/OrderFile/Orders/Order"); foreach (XmlElement Node in Nodes) { string S = Node.InnerText;
1
16440
by: Emsi | last post by:
Hello, how can I read values of child nodes with the XmlTextReader? File format: <root> <items> <item> <field1>value1</field1> <field2>value2</field2>
6
17309
by: Hans Kamp | last post by:
Is it possible to write a function like the following: string ReadURL(string URL) { .... } The purpose is that it reads the URL (determined by the parameter) and returns the string in which there is HTML-code, for example:
6
10216
by: Hans Kamp | last post by:
My program fails reading XML attributes. A fragment of the code is: private void showXmlNodeAtTreeNode(XmlNodeList xnl, TreeNode tn) { int i; for (i = 0; i < xnl.Count; i++) { XmlNode xn = xnl; XmlNodeType nodeType = xn.NodeType;
6
1691
by: ALI-R | last post by:
Hi All; I'm reading the following xml file into a Dataset but there are only 4 datatables in my dataset (which should be 5) Is that because I have two nodes with the same name (detail) in my xml file? how can I fix this? Thanks for your time. <?xml version="1.0" ?>
2
5106
by: news.microsoft.com | last post by:
Hi After conducting a several searches, I wasn't sure where to post this question. So my apologiesbefore hand for double posting this and possibly posting to the wrong forum(s). Okay, I have any application that uses the data access application building block from Microsoft's Enterprise Library (patterns and practices site). I want to allow the users to select the database connection. To do this, I thought I could read the...
4
1778
by: Ganesh Muthuvelu | last post by:
Hi STAN, Stan: Thanks for your response to my previous post on reading a XSD file using your article in "https://blogs.msdn.com/stan_kitsis/archive/2005/08/06/448572.aspx". it works quite well but I have one problem.. I am not able to read a Complex Content.. Here is a portion of the XSD that contains the complex content. I need to read the elements under it and could not get an handle to it.. Could you please help?
4
3793
by: scythemk | last post by:
Hi, I am writing a program that, everytime it executes, first loads all information from a file into a linked list of nodes, using struct to define it. After manipulating the data and receiving user input, the program once again outputs the linked list information to the same file. My problem is that when I'm first trying to get the info from the file into the linked list I get a bus error. My code is as follows: struct nodeType {...
0
6832
by: Skywave | last post by:
Hi All Firstly: I have searched everywhere! I couldn't find anything! Secondly: I am VERY new (1 and a half days) to C#, but I have been doing VB6 and VB.Net for years now. I want to learn C# ! Now that I have that out of the way... I want to write an application that will open multiple Garmin GPX files and display them in a tree view (The filename being the Text, with 2 sub-nodes), so that I can drag waypoints from one file to...
0
9646
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
9484
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
10350
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...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8983
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...
1
7505
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
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();...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.