?
Solved

Very simple Xml Question.

Posted on 2003-11-04
5
Medium Priority
?
236 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
[X]
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
  • 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 600 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

764 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