Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Oct 15, 2018 5:33 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: [solved]loadxml and savexml from xmldocument object/class
PostPosted: Sun Nov 11, 2012 6:59 pm 
Offline

Joined: Wed Sep 15, 2010 1:48 pm
Posts: 84
Fixed some errors, noticed that in mydebug program was generating a file, and on exit, deleted it.

put xml file in an application folder, and no problem.

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.

_________________
RS2012r2 Pro Win


Last edited by Dave_ on Wed Nov 14, 2012 8:42 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: loadxml and savexml from xmldocument object/class
PostPosted: Sun Nov 11, 2012 7:51 pm 
Offline

Joined: Sat Aug 22, 2009 9:44 am
Posts: 315
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
 Profile  
Reply with quote  
 Post subject: Re: loadxml and savexml from xmldocument object/class
PostPosted: Mon Nov 12, 2012 7:52 am 
Offline

Joined: Wed Sep 15, 2010 1:48 pm
Posts: 84
The location of output.txt is the desktop. xml.savexml DOES NOT work for some reason. Yet I can save it using a filestream, but does not load via .loadxml so I can parse it.

Frustrating. I took the example real provided, and it does not work.

_________________
RS2012r2 Pro Win


Top
 Profile  
Reply with quote  
 Post subject: Re: loadxml and savexml from xmldocument object/class
PostPosted: Mon Nov 12, 2012 9:25 am 
Offline

Joined: Sat Aug 22, 2009 9:44 am
Posts: 315
Can you clarify "xml.savexml DOES NOT work" please? Unless I skipped over it, I don't know if you're getting an error, an empty file, or no file saved at all. Is there already an "output.txt" that's read only, perhaps, so it can't overwrite it?


Top
 Profile  
Reply with quote  
 Post subject: Re: loadxml and savexml from xmldocument object/class
PostPosted: Wed Nov 14, 2012 6:44 am 
Offline

Joined: Wed Sep 15, 2010 1:48 pm
Posts: 84
xml.savexml is not saving the file, and xml.loadxml is not loading the file. I got preferences to work by a realsqldatabase, but it would be great to get the xml functions of RB to work...

since files created by RB are deleted by RB, this might be the problem. I will have to check my paths and save it in an application folder that does not get deleted on exit.

_________________
RS2012r2 Pro Win


Top
 Profile  
Reply with quote  
 Post subject: Re: [solved]loadxml and savexml from xmldocument object/clas
PostPosted: Wed Nov 14, 2012 8:47 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
Dave_ wrote:
xml.savexml is not saving the file


As I test it in my system, works perfectly. In a button's Action event I put the following code....

Dim outputXmlFile As FolderItem
outputXmlFile = GetSaveFolderItem(FileTypeXml.XMLFile, "Test.xml")

If outputXmlFile <> Nil Then

Dim tmpXmlDoc As new XmlDocument
Dim rootNode As XmlNode

rootNode = tmpXmlDoc.AppendChild(tmpXmlDoc.CreateElement("ROOT"))
rootNode.AppendChild(tmpXmlDoc.CreateElement("FIRST_CHILD")).AppendChild(tmpXmlDoc.CreateTextNode("first child"))
rootNode.AppendChild(tmpXmlDoc.CreateElement("SECOND_CHILD")).AppendChild(tmpXmlDoc.CreateTextNode("second child"))

tmpXmlDoc.SaveXml(outputXmlFile)

End If


And load a xml file also works fine.

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group