[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Very simple Xml Question.

Posted on 2003-11-04
5
Medium Priority
?
238 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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