SunQuest
           C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old December 17th, 2002, 06:15 AM
serg_dz serg_dz is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Ukraine
Posts: 5 serg_dz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question How to create xml on a fly

Can some body to help with xml tree creation on a fly. How can I add node?

Thanks.

Reply With Quote
  #2  
Old December 17th, 2002, 11:50 AM
CamLewis CamLewis is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 1 CamLewis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.)

Reply With Quote
  #3  
Old December 23rd, 2002, 08:02 AM
Wingman Wingman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Bavaria, Germany
Posts: 140 Wingman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 40 m 41 sec
Reputation Power: 6
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)

Reply With Quote
  #4  
Old January 2nd, 2003, 01:52 AM
serg_dz serg_dz is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Ukraine
Posts: 5 serg_dz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Great explanation

Thanks a lot!
This is a greatest explanation I could expact!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > How to create xml on a fly


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway