Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

XML Help (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: Putting 16x16 icons from other apps into a bevel button
Next thread: learning sqlite


XML Help   -   Craig Hoyt
  Re: XML Help   -   Jason Toews
   XML Help   -   Craig Hoyt
    Re: XML Help   -   Stefan Pantke
  Re: XML Help   -   Craig Hoyt

XML Help
Date: 19.08.05 02:01 (Thu, 18 Aug 2005 18:01:54 -0700)
From: Craig Hoyt
Could one of the XML Gurus' please give a quick XML 101 lesson? I am trying
to read/write/modify plists. So far through trial and error I've been able
to walk through a plist and retrieve selected values by key names and I've
also added nodes to a plist. I'm not sure I'm doing this correctly. I can't
seem to find a way to change a value of an existing key/value pair (I keep
adding a duplicate node pair to the list). Is there a simple way to extract
a value from a know key? I really know nothing on this subject and would
like to get a basic overview and the proper way to get values from known
keys/modify values from known keys/create & save xml files from scratch.

Thanks,
Craig
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: XML Help
Date: 19.08.05 17:17 (Fri, 19 Aug 2005 09:17:41 -0700)
From: Jason Toews
> Could one of the XML Gurus' please give a quick XML 101 lesson? I am
> trying
> to read/write/modify plists. So far through trial and error I've been able
> to walk through a plist and retrieve selected values by key names and I've
> also added nodes to a plist. I'm not sure I'm doing this correctly. I
> can't
> seem to find a way to change a value of an existing key/value pair (I keep
> adding a duplicate node pair to the list). Is there a simple way to
> extract
> a value from a know key? I really know nothing on this subject and would
> like to get a basic overview and the proper way to get values from known
> keys/modify values from known keys/create & save xml files from scratch.

I'm no guru, but I've done a little XML stuff, so I'll jump in.

First off, the RB Language Reference has some good info in the XMLDocument
section, which might help.

To modify nodes, I believe you'll have to read in the file and load the data
into an XMLDocument object. Once you have a valid XMLDocument in memory,
manipulate the data however you wish. When done, write out a new XML file,
replacing the old file.

Dim xDoc As XmlDocument
Dim xItemNode, xSectionNode As XmlNode
Dim xNodes As XmlNodeList
Dim xText, xItemName As String
Dim prefsFile As FolderItem
Dim ps As TextInputStream
Dim i, nodeCount As Integer

...

// read the file
ps = prefsFile.OpenAsTextFile
xText = ps.ReadAll
ps.Close

// instantiate an XmlDocument object
xDoc = New XmlDocument

// load data
xDoc.LoadXml xText

// now you can either iterate through all nodes...
nodeCount = (xDoc.ChildCount -1)
for i = 0 to nodeCount
xItemNode = xDoc.Child(i)
xItemName = xItemNode.LocalName
next

// ...or retrieve a specific list of nodes using xpath,
xNodes = xDoc.xql("/music/cd/artist")
nodeCount = xNodes.Length - 1
for i = 0 to nodeCount
xItemNode = xNodes.Item(i)
xItemName = xItemNode.LocalName
next

...

How to change the value for a given node will vary depending on the type and
structure of the node. It might be as simple as:

xItemNode.Value = "Jason"

Or:

xItemNode.FirstChild.Value = "Jason"

Or:

xItemNode.SetAttribute("NAME", "Jason")

Your best bet is to acquire the desired node by trial-and-error, then
examine the properties of that node in the debugger.

To create a new node, you might do something like the following:

xItemNode = xSectionNode.AppendChild(xDoc.CreateElement("AUTHOR"))
xItemNode.AppendChild(xDoc.CreateTextNode("Jason P. Toews"))

Once you have the XmlDocument populated correctly in memory, you can write
it out to a file, replacing the old one:

xText = xDoc.ToString
prefsFile = PreferencesFolder.Child("MyPrefs.xml")
ps = prefsFile.CreateTextFile
ps.Write xText
ps.Close

... and that's about the limits of my expertise. Hopefully, an expert will
chime in to correct the places where I got it wrong!

Jason

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

XML Help
Date: 19.08.05 17:42 (Fri, 19 Aug 2005 09:42:04 -0700)
From: Craig Hoyt
Could one of the XML Gurus' please give a quick XML 101 lesson? I am trying
to read/write/modify plists. So far through trial and error I've been able
to walk through a plist and retrieve selected values by key names and I've
also added nodes to a plist. I'm not sure I'm doing this correctly. I can't
seem to find a way to change a value of an existing key/value pair (I keep
adding a duplicate node pair to the list). Is there a simple way to extract
a value from a know key? I really know nothing on this subject and would
like to get a basic overview and the proper way to get values from known
keys/modify values from known keys/create & save xml files from scratch.

Thanks,
Craig

This is a resend as the first didn't sem to go through.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: XML Help
Date: 19.08.05 17:46 (Fri, 19 Aug 2005 18:46:28 +0200)
From: Stefan Pantke

Am 19.08.2005 um 18:42 schrieb Craig Hoyt:

> Could one of the XML Gurus' please give a quick XML 101 lesson? I
> am trying
> to read/write/modify plists. So far through trial and error I've
> been able
> to walk through a plist and retrieve selected values by key names
> and I've
> also added nodes to a plist. I'm not sure I'm doing this correctly.
> I can't
> seem to find a way to change a value of an existing key/value pair
> (I keep
> adding a duplicate node pair to the list). Is there a simple way to
> extract
> a value from a know key? I really know nothing on this subject and
> would
> like to get a basic overview and the proper way to get values from
> known
> keys/modify values from known keys/create & save xml files from
> scratch.

No need to learn full XML here.

Just download XMLDirectory (URL?). This nice class
parses plists quite nicely. You can read and write/update
plists.

Kinds
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: XML Help
Date: 20.08.05 06:36 (Fri, 19 Aug 2005 22:36:12 -0700)
From: Craig Hoyt
Thanks Stefan Pantke for the assist. I've bumbled together some code to
read an XML file and add nodes. Couldn't find XMLDirectory you spoke of. I
hunted around RB Garage. Most items there are old and seem to bow to RB's
XML handling thats rolled into the IDE. I'm sure RB's documentation is
adequate if you know XML already but I don't. It isn't much help at all.
What I need is a quick simple explanation of how it all works. and basic
examples how to retrieve a value from a know key, add a key/value pair/
modify a value from a know key (and I guess test if the key is present). I
realize it's probably simple but I just don't get it. I looked on the
internet for some clue but there I find XML in reference to HTML and
nothing I can relate to what I'm doing in RB2005k.

Thanks again,
Craig

>
>Message: 5
>Subject: Re: XML Help
>From: Stefan Pantke <<email address removed>>
>Date: Fri, 19 Aug 2005 18:46:28 +0200
>
>Am 19.08.2005 um 18:42 schrieb Craig Hoyt:
>
>> Could one of the XML Gurus' please give a quick XML 101 lesson? I
>> am trying
>> to read/write/modify plists. So far through trial and error I've
>> been able
>> to walk through a plist and retrieve selected values by key names
>> and I've
>> also added nodes to a plist. I'm not sure I'm doing this correctly.
>> I can't
>> seem to find a way to change a value of an existing key/value pair
>> (I keep
>> adding a duplicate node pair to the list). Is there a simple way to
>> extract
>> a value from a know key? I really know nothing on this subject and
>> would
>> like to get a basic overview and the proper way to get values from
>> known
>> keys/modify values from known keys/create & save xml files from
>> scratch.
>
>No need to learn full XML here.
>
>Just download XMLDirectory (URL?). This nice class
>parses plists quite nicely. You can read and write/update
>plists.
>
>Kinds
>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>