473,387 Members | 1,892 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,387 software developers and data experts.

xml node

Hello,
How can I get a xml node from a XmlTextReader?
Thanks a lot!

*** Sent via Developersdex http://www.developersdex.com ***
Nov 12 '05 #1
5 1324


juli jul wrote:
How can I get a xml node from a XmlTextReader?


The XmlTextReader itself has no method for that but you can pass the
reader to the method ReadNode of an XmlDocument object which then
creates the node.
Here is a simple example that uses the reader to read through an XML
document, looking for an element node with node name 'god' and then
creates an XmlElement of that:
XmlTextReader xmlReader = new XmlTextReader(args[0]);
XmlDocument xmlDocument = new XmlDocument();
XmlElement god = null;
while (xmlReader.Read()) {
if (xmlReader.NodeType == XmlNodeType.Element &&
xmlReader.Name == "god")
{
god = (XmlElement) xmlDocument.ReadNode(xmlReader);
break;
}
}
xmlReader.Close();
if (god != null) {
Console.WriteLine("Found {0} with OuterXml:\r\n{1}", god,
god.OuterXml);
}
}

Here is the documentation of ReadNode:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlDocumentClassReadNodeTopic.asp>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Thanks ,but what I need is to send a "main" node,a node which can be
taken by the recursive function and get to all the other Xml Nodes.How
do I do that?
Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Nov 12 '05 #3


juli jul wrote:
but what I need is to send a "main" node,a node which can be
taken by the recursive function and get to all the other Xml Nodes.How
do I do that?


I am not sure I understand what you want to do, perhaps simply calling
the Load method of an XmlDocument on an XmlTextReader is all you are
looking for:
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(new XmlTextReader(urlGoesHere));

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #4

Hello,
I want to go via all the nodes in the xml doc and that's why I need a
main XmlNOde which will provide me recursivly to go though all of the
elements in the document.
How can I do it?
Thank you!


*** Sent via Developersdex http://www.developersdex.com ***
Nov 12 '05 #5


juli jul wrote:

I want to go via all the nodes in the xml doc and that's why I need a
main XmlNOde which will provide me recursivly to go though all of the
elements in the document.


The main node will be an instance of XmlDocument then as already posted
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(new XmlTextReader(someURL));
Then you can access the ChildNodes of the xmlDocument and recursively
walk the tree.
Or if you wan the root element you can then access
xmlDocument.DocumentElement

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #6

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

Similar topics

8
by: J Peterman | last post by:
Im having a nightmare trying to understand these nodes and linked lists. I've posted my code for my node.h, node.cpp, linkedlist.h and linkedlist.cpp files in separates replies. Can someone...
2
by: Ralf Wahner | last post by:
Dear Masters of XSLT Could I ask you for a clue on the following question? I'd like to use XSLT to transform an XML source file to LaTeX. In the following small example the <para> Element...
6
by: Chuck | last post by:
What's the difference between using "catalog node" and catalog admin node"? -- Chuck Remove "_nospam" to reply by email
3
by: stabbert | last post by:
We are running DB2 UDB 8.1.6 in a partitioned environment where we have 8 physical nodes. We have a process that remotely connects to each individual node and loads some data. By setting the...
5
by: Jeroen Ceuppens | last post by:
I need to put a new node at the end of the tree, that end is not te lowest in de list but the deepest (the one with the most + before it) Node A Node 1 Node 2 Node 3 Node 4: Deepest Node B:...
3
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an...
8
by: Dylan Parry | last post by:
Hi folks, I have an XML node called "myNode" and it contains: "This is some text" Now I can use the myNode.nodeValue property to get the string of text above. But say myNode contains: ...
6
by: Derek Hart | last post by:
I bring in an xml file into vb.net by using xmlDoc.LoadXml(XMLString) - I run xpath statements against the xml file to grab data from it, so I use, as an example, //Vehicles/Vehicles/@make to get...
9
by: Moses | last post by:
Hi All, How to check weather a node has sibling? Is there any function like " hasChildNodes() " Thanks in Advance Moses
3
by: Kane | last post by:
When you create node 1 you allocate memory and link it Again when you create node 2 you would allocate memory for that node in a different section of the code. Is there more efficient way where I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
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,...

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.