[Info-vax] DCL and scripting
Arne Vajhøj
arne at vajhoej.dk
Wed Dec 12 21:16:20 EST 2018
On 12/12/2018 8:58 PM, Arne Vajhøj wrote:
> On 12/12/2018 8:34 PM, Dave Froble wrote:
>> On 12/12/2018 7:49 PM, Arne Vajhøj wrote:
>>> Regex is a bit cryptic. But it can be useful.
>>>
>>> But I will say that all programmers should know SQL, regex and XPath.
>>
>> I know some SQL. I don't even know what regex and xpath is.
>
> regex is a way to find patterns in text.
>
> XPath is a way to select parts of an XML document.
>
>> I guess
>> according to you I should stick to flying. Oh well, much more fun
>> anyway.
>>
>> Now if it would just warm up ....
>
> Or maybe something to study during Christmas vacation.
>
> :-)
Simple XPath example in VB.NET:
Imports System
Imports System.Xml
Namespace DF2
Public Class Program
Public Shared Sub Main(args As String())
Dim xml As String = "<all>" & vbCrLf & _
" <one>" & vbCrLf & _
" <a id=""1""/>" & vbCrLf & _
" <b>A</b>" & vbCrLf & _
" </one>" & vbCrLf & _
" <one>" & vbCrLf & _
" <a id=""2""/>" & vbCrLf & _
" <b>BB</b>" & vbCrLf & _
" </one>" & vbCrLf & _
" <one>" & vbCrLf & _
" <a id=""3""/>" & vbCrLf & _
" <b>CCC</b>" & vbCrLf & _
" </one>" & vbCrLf & _
"</all>"
Console.WriteLine(xml)
Dim doc As New XmlDocument()
doc.LoadXml(xml)
For Each n As XmlNode In doc.SelectNodes("/all/one")
Console.WriteLine(n.SelectSingleNode("a/@id").Value & "
" & n.SelectSingleNode("b/text()").Value)
Next
End Sub
End Class
End Namespace
Output:
<all>
<one>
<a id="1"/>
<b>A</b>
</one>
<one>
<a id="2"/>
<b>BB</b>
</one>
<one>
<a id="3"/>
<b>CCC</b>
</one>
</all>
1 A
2 BB
3 CCC
Arne
More information about the Info-vax
mailing list