Solved

Very simple Xml Question.

Posted on 2003-11-04
5
226 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now