New topic: 

Concatenate XML parts into one big piece.

<http://forums.realsoftware.com/viewtopic.php?t=46046>

         Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic          Author  
Message        Carharttguy          Post subject: Concatenate XML parts into 
one big piece.Posted: Mon Nov 26, 2012 1:16 pm                         
Joined: Wed Sep 17, 2008 2:45 pm
Posts: 203                Hello,

The following question is one from my lack of knowlegde of RB and XML.
I have a class, that has a .toXML function.

But there are more instances of that class, and I want to concatenate all the 
output from those instances into one, bigger XML file.

Now the toXML returns a string. Ofcourse that can be merged, but every 
xmlDocument starts with <?xml version ..  encoding..?>. So that cannot be 
concatenated. (Without stripping that line, but that would be dirty.)

I now have this code: 

Dim xml as XmlDocument
Dim root, _properties, _property, _events, _event As XmlNode

xml = New XmlDocument
root = xml.AppendChild(xml.CreateElement("control"))

_properties = root.AppendChild(xml.CreateElement("properties"))
For each p as aProperty in Properties.toArray
  _property = _properties.AppendChild(xml.CreateElement("property"))
  _property.SetAttributeNode(xml.CreateAttribute("name"))
  _property.SetAttribute("name", p.Name)
  _property.SetAttributeNode(xml.CreateAttribute("propertycode"))
  _property.SetAttribute("propertycode", CStr(p.PropertyCode))
  _property.AppendChild(xml.CreateTextNode(p.Value))
Next

_events = root.AppendChild(xml.CreateElement("events"))
For each ev As aEvent in Events.toArray
  _event = _events.AppendChild(xml.CreateElement("event"))
  _event.SetAttributeNode(xml.CreateAttribute("default"))
  _event.SetAttribute("default", cStr(ev.Default))
  _event.SetAttributeNode(xml.CreateAttribute("name"))
  _event.SetAttribute("name", ev.Name)
  _event.AppendChild(xml.CreateTextNode(ev.Code))
Next

Return xml.ToString


Is there a better way to accomplish what I want?

Thanks in advance.      
_________________
My native language is not English.  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to