Oh, have forgotten to answer to this post.
Create on your desktop the file "Stocks.xml" with this text in the file:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?xml version="1.0" encoding="UTF-8"?>
<stocks>
<stock>
<symbol>Citibank</symbol>
<price>100</price>
<quantity>1000</quantity>
</stock>
<stock>
<symbol>Axis bank</symbol>
<price>90</price>
<quantity>2000</quantity>
</stock>
</stocks>
|
Then this Jabaco-port works:
|
Jabaco Source
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
Import java#io#File
Import javax#xml#parsers#DocumentBuilder
Import javax#xml#parsers#DocumentBuilderFactory
Import org#w3c#dom#Document
Import org#w3c#dom#Element
Import org#w3c#dom#Node
Import org#w3c#dom#NodeList
Public Sub main(ByJava args() As String)
Dim stocks As New File("Stocks.xml")
Dim dbFactory As DocumentBuilderFactory = DocumentBuilderFactory.newInstance
Dim dBuilder As DocumentBuilder = dbFactory.newDocumentBuilder
Dim doc As Document = dBuilder.parse(stocks)
doc.getDocumentElement.normalize
System.out.println("root of xml file " & doc.getDocumentElement.getNodeName)
Dim nodes As NodeList = doc.getElementsByTagName("stock")
System.out.println("==========================")
Dim i As Integer
For i = 0 To nodes.getLength -1
Dim jnode As org#w3c#dom#Node = nodes.item(i)
If jnode.getNodeType = jnode.ELEMENT_NODE Then
Dim jelement As Element = Cast(jnode, Element)
System.out.println("Stock Symbol: " & getValue("symbol", jelement))
System.out.println("Stock Price: " & getValue("price", jelement))
System.out.println("Stock Quantity: " & getValue("quantity", jelement))
End If
Next i
MsgBox ""
End Sub
Private Function getValue(tag As String, jelement As Element) As String
Dim nodes As NodeList = jelement.getElementsByTagName(tag).item(0).getChildNodes
Dim zNode As org#w3c#dom#Node = nodes.item(0)
Dim jnode As org#w3c#dom#Node = Cast(zNode, org#w3c#dom#Node)
getValue = jnode.getNodeValue
End Function
|
Greatings
theuserbl