Click here to Skip to main content
15,913,221 members
Home / Discussions / XML / XSL
   

XML / XSL

 
GeneralRe: Walking Through XML in JavaScript Visiting All ChildNodes Pin
palbano24-Feb-03 4:41
palbano24-Feb-03 4:41 
Generalproblem creating XML programatically Pin
illsorted19-Feb-03 6:36
illsorted19-Feb-03 6:36 
GeneralRe: problem creating XML programatically Pin
Philip Fitzsimons24-Feb-03 2:32
Philip Fitzsimons24-Feb-03 2:32 
GeneralDifferent between XSL and XSLT Pin
Firas Rashid17-Feb-03 2:05
Firas Rashid17-Feb-03 2:05 
GeneralRe: Different between XSL and XSLT Pin
Philip Fitzsimons19-Feb-03 1:58
Philip Fitzsimons19-Feb-03 1:58 
QuestionMy xml file is displayed as a long string. How do I insert newlines? Pin
lnong16-Feb-03 1:47
lnong16-Feb-03 1:47 
AnswerRe: My xml file is displayed as a long string. How do I insert newlines? Pin
Richard Deeming17-Feb-03 3:38
mveRichard Deeming17-Feb-03 3:38 
QuestionAm I creating an XML document correctly? Pin
lnong16-Feb-03 1:29
lnong16-Feb-03 1:29 
The C# code I'm using is shown below. The output file looks almost exactly how a basic XML file should look, I believe. My only concern is that how come the code to create it looks rather inefficient? How come I need to do "folder = doc.CreateElement("folder")" for EVERY new node that I create?? Can't I just use the "folder" object as a template for a folder element? Shouldnt all I need to do is set the attribute value and the inner text, and then reuse "folder" element object to append the new node? This is what I am saying:

<br />
XmlElement folder = doc.CreateElement("folder");<br />
<br />
// Add first node<br />
folder.SetAttribute("name", "folder 1");<br />
folder.InnerText = "1st Node";<br />
root.AppendChild(folder);<br />
			<br />
// Add second node<br />
folder.SetAttribute("name", "folder 2");<br />
folder.InnerText = "2nd Node";<br />
root.AppendChild(folder);<br />


However, that did not work. Here's the (whole) code that does work for me:

<br />
XmlDataDocument doc = new XmlDataDocument();<br />
XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", null, null);<br />
doc.InsertAfter(declaration, null);<br />
<br />
XmlElement root = doc.CreateElement("file_system");<br />
doc.InsertAfter(root, declaration);<br />
<br />
XmlElement folder;<br />
<br />
// Add first node<br />
folder = doc.CreateElement("folder");<br />
folder.SetAttribute("name", "folder 1");<br />
folder.InnerText = "1st Node";<br />
root.AppendChild(folder);<br />
			<br />
// Add second node<br />
folder = doc.CreateElement("folder");<br />
folder.SetAttribute("name", "folder 2");<br />
folder.InnerText = "2nd Node";<br />
root.AppendChild(folder);<br />
<br />
// Output to file<br />
XmlTextWriter writer = new XmlTextWriter(@"d:\XMLTest.xml", null);<br />
doc.WriteTo(writer);<br />
writer.Close();<br />


Is this the correct and most efficient way to create an XML document dynamically? Please share with me better solutions. Thanks.
AnswerRe: Am I creating an XML document correctly? Pin
Philip Fitzsimons19-Feb-03 2:06
Philip Fitzsimons19-Feb-03 2:06 
QuestionHow to store XML content into C/C++ structure Pin
15-Feb-03 10:23
suss15-Feb-03 10:23 
AnswerRe: How to store XML content into C/C++ structure Pin
Nitron18-Feb-03 14:19
Nitron18-Feb-03 14:19 
AnswerRe: How to store XML content into C/C++ structure Pin
palbano19-Feb-03 12:22
palbano19-Feb-03 12:22 
GeneralRe: How to store XML content into C/C++ structure Pin
palbano19-Feb-03 12:24
palbano19-Feb-03 12:24 
GeneralXML Docs/Comments Pin
mgarwood15-Feb-03 6:42
mgarwood15-Feb-03 6:42 
GeneralI need your suggestion about storing data as XML Pin
lnong14-Feb-03 14:46
lnong14-Feb-03 14:46 
GeneralRe: I need your suggestion about storing data as XML Pin
Nitron18-Feb-03 14:24
Nitron18-Feb-03 14:24 
GeneralXML using C/C++ Pin
vietdynamite14-Feb-03 1:54
vietdynamite14-Feb-03 1:54 
GeneralRe: XML using C/C++ Pin
palbano14-Feb-03 5:04
palbano14-Feb-03 5:04 
GeneralRe: XML using C/C++ Pin
15-Feb-03 9:36
suss15-Feb-03 9:36 
GeneralAnother XPath Question Pin
James McCutcheon12-Feb-03 13:41
James McCutcheon12-Feb-03 13:41 
GeneralRe: Another XPath Question Pin
Christian Graus12-Feb-03 14:40
protectorChristian Graus12-Feb-03 14:40 
GeneralRe: Another XPath Question Pin
Michael A. Barnhart13-Feb-03 7:03
Michael A. Barnhart13-Feb-03 7:03 
GeneralRe: Another XPath Question Pin
Michael Dunn13-Feb-03 19:07
sitebuilderMichael Dunn13-Feb-03 19:07 
GeneralXPath question Pin
Marc Clifton12-Feb-03 10:55
mvaMarc Clifton12-Feb-03 10:55 
GeneralRe: XPath question Pin
Michael A. Barnhart13-Feb-03 6:51
Michael A. Barnhart13-Feb-03 6:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.