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

string to XmlNode

Given a string value representing an Xml-Element. What is the easyiest way
to get a XmlNode from it?
Sep 13 '06 #1
3 52059


Christof Nordiek wrote:
Given a string value representing an Xml-Element. What is the easyiest way
to get a XmlNode from it?
With .NET 1.x e.g.
XmlTextReader xmlReader = new XmlTextReader(new
StringReader(stringVariable));

// if you already have an XmlDocument then use that, otherwise
// create one
XmlDocument xmlDocument = new XmlDocument();
XmlNode node = xmlDocument.ReadNode(xmlReader);

The node can the be inserted/used as needed.

With .NET 2.0 you should use XmlReader.Create to create an XmlReader,
otherwise the code is the same. And XmlTextReader is still around in
..NET 2.0 so the code would even work without change, only using
XmlReader.Create is preferred in .NET 2.0.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 13 '06 #2
Check the documentation out on MSDN here

http://msdn2.microsoft.com/en-us/library/fb63z0tw.aspx

"Christof Nordiek" <cn@nospam.dewrote in message
news:e8**************@TK2MSFTNGP06.phx.gbl...
Given a string value representing an Xml-Element. What is the easyiest way
to get a XmlNode from it?

Sep 13 '06 #3
Thanks Martin

exactly what i needed.

"Martin Honnen" <ma*******@yahoo.deschrieb im Newsbeitrag
news:Ou*************@TK2MSFTNGP06.phx.gbl...
>

Christof Nordiek wrote:
>Given a string value representing an Xml-Element. What is the easyiest
way to get a XmlNode from it?

With .NET 1.x e.g.
XmlTextReader xmlReader = new XmlTextReader(new
StringReader(stringVariable));

// if you already have an XmlDocument then use that, otherwise
// create one
XmlDocument xmlDocument = new XmlDocument();
XmlNode node = xmlDocument.ReadNode(xmlReader);

The node can the be inserted/used as needed.

With .NET 2.0 you should use XmlReader.Create to create an XmlReader,
otherwise the code is the same. And XmlTextReader is still around in .NET
2.0 so the code would even work without change, only using
XmlReader.Create is preferred in .NET 2.0.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Sep 13 '06 #4

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

Similar topics

2
by: David Elliott | last post by:
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString"...
3
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
5
by: Paul | last post by:
Here I have the definition of an XmlNode which is a property (PayPreference) on my Customer class containing an enum describing how the customer will pay. <PayPerference...
7
by: Jeppe BS | last post by:
hi I got an XmlNode called xNode Is there a way to convert it so it fits into a string ?
3
by: Mae | last post by:
Dear All, I have a problem here, I'm using C# Webform calling a webservices. The webservices return me a XMLnode, using this XMLnode I want to convert it to dataset so I can bind to the...
7
by: BluDog | last post by:
Hi I am trying to store an image in an xml file, i vcan store it fine but the retreval is a bit of a problem: To String: Dim ms As New IO.MemoryStream Dim arrImage() As Byte...
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it...
5
by: Sharon | last post by:
How can I get the full XML path (as string) of a specific XmlNode ? -- Thanks Sharon
14
by: sani723 | last post by:
i ma usin gthe extension object in XSLT and then passing a string to XSLT like this for(int i=0;i<xmlnode.Count;i++) { XmlAttributeCollection xmlattrc = xmlnode.Attributes; ...
5
by: =?Utf-8?B?VGhlIE1hbiBGcm9tIFNRTA==?= | last post by:
I'm having the darndest XML config file problem that I really need help with. I'm supporting a .NET 1.1 desktop application with its own config file, and I implement IConfigurationSectionHandler...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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
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...
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...

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.