New topic: 

loadxml and savexml from xmldocument object/class

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

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        Dave_          Post subject: loadxml and savexml from 
xmldocument object/classPosted: Sun Nov 11, 2012 6:59 pm                        
 
Joined: Wed Sep 15, 2010 1:48 pm
Posts: 60                here is my save xml code, real simple. When I use 
.savexml, it does not save on windows. If I use filestream, it saves, but does 
not load via .loadxml or via a string from a filestream

save xml: 

Dim xml as XmlDocument
dim root, listbox2attributes, listbox2attributefontsize, 
listbox2attributecolwidths as xmlnode
dim f as FolderItem
dim t as string
dim filestream as TextOutputStream


f = getfolderitem("output.txt")

if f <> nil then
  
  xml = new XmlDocument
  root = xml.AppendChild(xml.CreateElement("root"))
  listbox2attributes = root.AppendChild(xml.CreateElement("listbox2attributes"))
  listbox2attributefontsize = 
listbox2attributes.AppendChild(xml.CreateElement("listbox2attributefontsize"))
  
listbox2attributefontsize.AppendChild(xml.CreateTextNode(str(listbox2.TextSize)))
  listbox2attributecolwidths = 
listbox2attributes.AppendChild(xml.CreateElement(" listbox2attributecolwidths"))
  
listbox2attributecolwidths.AppendChild(xml.CreateTextNode(listbox2.ColumnWidths))
  
  msgbox(xml.ToString)
  
  textarea1.text = xml.ToString
  
  xml.SaveXml(f)
  
  'If f <> Nil then
  'filestream=TextOutputStream.Create(f)
  'filestream.Write(t)
  'filestream.Close
  'End if
  
  
  
  
  
  msgbox("file saved")
end if



loadxml code: 

dim xmltext as string

Dim f As FolderItem
f = GetFolderItem("CreateExample.txt")
If f <> Nil Then
  If f.Exists Then
  // Be aware that TextInputStream.Open could raise an exception
  Dim t As TextInputStream
  Try
  t = TextInputStream.Open(f)
  t.Encoding = Encodings.MacRoman
  xmltext = t.ReadAll
  Catch e As IOException
  t.Close
  MsgBox("Error accessing file.")
  End Try
  End If
End If

msgbox(xmltext)



dim x as new XmlDocument
x.LoadXml(xmltext)
// also tried x.loadxml(f) '
// check first node of document:
dim n as XmlNode = x.FirstChild
MsgBox n.Name // doc node

// and now walk over all sub nodes:
dim e as XmlNode = n.FirstChild
while e<>Nil
  MsgBox e.name+": "+e.FirstChild.value
  
  e = e.NextSibling
wend


According to the examples, this should work.      
_________________
rb2011 Pro r2  
                             Top                wbgookin          Post subject: 
Re: loadxml and savexml from xmldocument object/classPosted: Sun Nov 11, 2012 
7:51 pm                         
Joined: Sat Aug 22, 2009 9:44 am
Posts: 301                When you say it isn't saving, what does that mean? Is 
it saving an empty file, or is it just not there?  Are you running in the IDE, 
or a compiled version?  Can you try saving it to the desktop instead of just 
saying "getfolderitem("output.txt")" so you know for sure where it's supposed 
to be going?

Bill   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
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