Solved

Very simple Xml Question.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get String split 5 47
How to measure sizes and angles in scanned images ? 3 52
Angular JS Route 3 47
How would you add MULTITHREADING to the attached C# code? 4 51
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

23 Experts available now in Live!

Get 1:1 Help Now