[Info-vax] Any Way to Pass Arrays of Strings from C to Basic?
Arne Vajhøj
arne at vajhoej.dk
Fri Nov 8 13:53:30 EST 2019
On 11/8/2019 10:18 AM, Dave Froble wrote:
> On 11/8/2019 8:16 AM, Simon Clubley wrote:
>> If there are not, then I don't see why you can't just use one of
>> the various C language SAX parsers and register your BASIC function
>> as the callback handler if you didn't want to bother with one of
>> the DOM style parsers.
>
> If a simple routine similar to:
>
> 100 !************************************************************
> ! Parse a String
> !************************************************************
> !
> SUB PARSE( STG$ , DELIM$ , FRONT$ , BACK$ )
> !
> ! STG$ - String to parse
> ! DELIM$ - Delimiter string
> ! FRONT$ - Segment of string preceeding delimiter
> ! BACK$ - Segment of string following delimiter
> !
> !************************************************************
> !
> OPTION SIZE=( INTEGER WORD , REAL DOUBLE )
>
> Z% = INSTR( 1% , STG$ , DELIM$ ) ! Search for
> delimiter
> Z% = LEN(STG$)+1% UNLESS Z% ! Not found,
> whole stri
> ng
> FRONT$ = LEFT( STG$ , Z%-1% ) ! Preceeding
> segment
> BACK$ = RIGHT( STG$ , Z%+LEN(DELIM$) ) ! Following
> segment
> !
> SUBEND
>
> is available, then just about anything can be extracted with two calls
> to the routine. For example:
>
> <customer_number>987654321</customer_number>
>
> can easily get the data by parsing first the front tag, then the rear tag.
>
> I just don't see why I should f*** around with anyone else's bloatware,
> which does so much more than what I need.
I think it depends on whether you are parsing XML or
parsing DFSML (Dave Froble Simple Markup Language).
:-)
It is actually not trivial to parse XML. Nested tags, CDATA
sections and namespaces can make it tricky to get right.
Example (VB.NET):
Imports System
Imports System.Xml
Namespace E
Public Class Program
Public Shared Sub Main(args As String())
Dim xmlstr As String = "<a xmlns:df='http://df2'><b
xmlns='http://df1'><x><![CDATA[ABC<x></x>]]></x></b><c
xmlns='http://df2'><x><![CDATA[DEF<x></x>]]></x></c><c
xmlns='http://df3'><x><![CDATA[GHI<x></x>]]></x></c><df:c><df:x><![CDATA[JKL<x></x>]]></df:x></df:c></a>"
Dim doc As New XmlDocument()
doc.LoadXml(xmlstr)
Dim nsm As New XmlNamespaceManager(doc.NameTable)
nsm.AddNamespace("df1", "http://df1")
nsm.AddNamespace("df2", "http://df2")
nsm.AddNamespace("df3", "http://df3")
For Each n As XmlNode In doc.SelectNodes("/a/df2:c/df2:x/text()", nsm)
Console.WriteLine(n.Value)
Next
Console.ReadKey()
End Sub
End Class
End Namespace
correctly outputs:
DEF<x></x>
JKL<x></x>
It finds all text inside a namespace http://df2 tag x element
inside inside a namespace http://df2 tag c element inside a
no namespace a element.
I would not want to code that using string functions.
Arne
More information about the Info-vax
mailing list