|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Can some body to help with xml tree creation on a fly. How can I add node?
Thanks. |
|
#2
|
|||
|
|||
|
What environment are you working in?
I'm not the most experienced .NET programmer you'll find around here, I'm sure, but I'd start with the XmlDataDocument object documentation, and grow from there. I designed a fairly simple schema and a program to update a file based on that schema with very litte trouble in VS.NET, and I hadn't worked with it before... I'd get very familiar with the documentation and how to find stuff that you need... I'm not quite there yet, but I'm learning. ![]() (I'm mostly a web guy, but have been doing some RAD lately as well.) |
|
#3
|
|||
|
|||
|
System.Xml.XmlDocument/MSXML2.DOMDocument
myDoc.LoadXML(String xml): loads a xml document out of an string myDoc.Load(String filename); loads a xml doc from a file myDoc.Save(String filename); saves a xml doc to a file --- myDoc.CreateElement(String name) myDoc.CreateAttribute(String name) myDoc.CreateComment(String cm) ... Creates the different types of nodes --- Output is different between MSXML4 and MSXML.Net: MSXML4: myDoc.xml MSXML.Net: myDoc.OuterXml Returns this doc as String Attributes: myNode.setAttribute(name, value); myNode.getAttribute(name); Nodes: myNode.AppendChild(node); myNode.ReplaceChild(new, old); myNode.InsertAfter(new, ref); // only MSXML.Net myNode.InsertBefore(new, ref); and for node navigation: myNode.nextSibling: returns the node right in the list myNode.previousSibling: returns the node left in the list myNode.parentNode: returns the parent node myNode.childNodes: returns all child nodes Example C#: XmlDocument myDoc = new XmlDocument(); XmlElement myEle = myDoc.CreateElement("root"); for (int i = 0; i < 3; i++) { XmlElement myChild = myDoc.CreateElement("child"); myChild.SetAttribute("index", i); myEle.AppendChild(myChild); } Console.WriteLine(myEle.OuterXml); -> output: <root><child index="1" /><child index="2" /><child index="3" /></root> Example VB6: Dim myDoc As DOMDocument Set myDoc = new DOMDocument Dim myEle As IXMLDOMElement Dim myChild As IXMLDOMElement Set myEle = myDoc.CreateElement("root") Dim i As Long For i = 0 To 3 Set myChild = myDoc.CreateElement("child") myChild.SetAttribute "index", i myEle.AppendChild(myChild) Next Debug.Print myDoc.xml --> output same as above. See? It's very easy once you get the main methods since it's always the same (and btw - for the DHTML coders out there...doesn't this remind you on something? ;-) the javascript/html doc is *exactly* the same thing) |
|
#4
|
|||
|
|||
|
Great explanation
Thanks a lot!
This is a greatest explanation I could expact! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > How to create xml on a fly |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|