Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Very simple Xml Question.

Posted on 2003-11-04
5
233 Views
Last Modified: 2010-04-16
I want to create an XmlElement (or any type of XmlNode where I can setAttributes) and then get the string representation (outerXml()).  XmlElement and XmlNode are both not implementable by themselves, what should I use?  
0
Comment
Question by:jjacksn
  • 2
  • 2
5 Comments
 
LVL 5

Author Comment

by:jjacksn
ID: 9681275
Also, how would I creat another child node and append it to this node.  This is all for the purpose of just ending up with a string representation to pass to something else.
0
 
LVL 9

Expert Comment

by:msdixon
ID: 9681478
// this assumes doc is an XmlDocument type, and i can't remember if this method returns an XmlElement or XmlNode....
XmlElement element = doc.SelectSingleNode(xpath);
0
 
LVL 2

Accepted Solution

by:
bertvermeerbergen earned 150 total points
ID: 9681507
Use the XmlDocument class in System.Xml

XmlDocument doc = new XmlDocument();
XmlElement e1 = doc.CreateElement(...);
XmlAttribute a = doc.CreateAttribute(...);
e1.Attributes.Append(a);

XmlElement e2 = doc.CreateElement(...);
e.AppendChild(e2);

doc.DocumentElement.AppendChild(e1);
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9681611
Yeah, that's what I did, I thought maybe there was a better way than creating a doc....
0
 
LVL 2

Expert Comment

by:bertvermeerbergen
ID: 9681857
What would you define as a 'better' way ?
The framework offers you all the functionality you need in the XmlDocument class, ready to use.
If you really don't want the XmlDocument class, have a look at XmlWriter.  It is less flexible as the order of calls is important,  but if your input is in the correct order you may like it better.  You can pass a StringWriter to the constructor to get the result in a string (there is no OuterXml(), of course).
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question