ik was aan het stuntelen met xml en wilde een voorbeeldje werkend krijgen. De methode van het voorbeeld staat op internet en in 2 van me boeken het zelfde dus hij zou wel moeten werken maar hier dus niet.
Eerst een voorbeeldje wat wel werkt hier wat dus iig laat zien dat ik wel uit de xml kan lezen.
Deze doet het dus iig goed.
Nu de gene die niet werkt:
na een seconde of 2 krijg ik dan de volgende error:
An unhandled exception of type 'System.Xml.XmlException' occurred in system.xml.dll
Additional information: System error.
iemand een idtje of iemand die ziet wat ik fout doe ?
Eerst een voorbeeldje wat wel werkt hier wat dus iig laat zien dat ik wel uit de xml kan lezen.
Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| Dim textReader As XmlTextReader = New XmlTextReader("test.xml") textReader.Read() ' If the node has value If TextReader.HasValue Then ' Move to fist element TextReader.MoveToElement() txtXML.Text &= NewLine & "XmlTextReader Properties Test" txtXML.Text &= NewLine & "===================" ' Read this element's properties and display them on console txtXML.Text &= NewLine & "Name:" + textReader.Name txtXML.Text &= NewLine & "Base URI:" + textReader.BaseURI txtXML.Text &= NewLine & "Local Name:" + textReader.LocalName txtXML.Text &= NewLine & "Attribute Count:" + textReader.AttributeCount.ToString() txtXML.Text &= NewLine & "Depth:" + textReader.Depth.ToString() txtXML.Text &= NewLine & "Line Number:" + textReader.LineNumber.ToString() txtXML.Text &= NewLine & "Node Type:" + textReader.NodeType.ToString() txtXML.Text &= NewLine & "Attribute Count:" + textReader.Value.ToString() Else End If |
Deze doet het dus iig goed.
Nu de gene die niet werkt:
Visual Basic .NET:
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| Dim ws, pi, dc, cc, ac, et, el, xd As Integer ' Read a document Dim textReader As XmlTextReader = New XmlTextReader("test.xml") ' Read until end of file While textReader.Read() Dim nType As XmlNodeType = textReader.NodeType ' If node type us a declaration If nType = XmlNodeType.XmlDeclaration Then Console.WriteLine("Declaration:" + TextReader.Name.ToString()) xd = xd + 1 End If ' if node type is a comment If nType = XmlNodeType.Comment Then Console.WriteLine("Comment:" + textReader.Name.ToString()) cc = cc + 1 End If ' if node type us an attribute If nType = XmlNodeType.Attribute Then Console.WriteLine("Attribute:" + textReader.Name.ToString()) ac = ac + 1 End If ' if node type is an element If nType = XmlNodeType.Element Then Console.WriteLine("Element:" + textReader.Name.ToString()) el = el + 1 End If ' if node type is an entity If nType = XmlNodeType.Entity Then Console.WriteLine("Entity:" + textReader.Name.ToString()) et = et + 1 End If ' if node type is a Process Instruction If nType = XmlNodeType.Entity Then Console.WriteLine("Entity:" + textReader.Name.ToString()) pi = pi + 1 End If ' if node type a document If nType = XmlNodeType.DocumentType Then Console.WriteLine("Document:" + textReader.Name.ToString()) dc = dc + 1 End If ' if node type is white space If nType = XmlNodeType.Whitespace Then Console.WriteLine("WhiteSpace:" + textReader.Name.ToString()) ws = ws + 1 End If End While Console.WriteLine("Total Comments:" + cc.ToString()) Console.WriteLine("Total Attributes:" + ac.ToString()) Console.WriteLine("Total Elements:" + el.ToString()) Console.WriteLine("Total Entity:" + et.ToString()) Console.WriteLine("Total Process Instructions:" + pi.ToString()) Console.WriteLine("Total Declaration:" + xd.ToString()) Console.WriteLine("Total DocumentType:" + dc.ToString()) Console.WriteLine("Total WhiteSpaces:" + ws.ToString()) |
na een seconde of 2 krijg ik dan de volgende error:
An unhandled exception of type 'System.Xml.XmlException' occurred in system.xml.dll
Additional information: System error.
iemand een idtje of iemand die ziet wat ik fout doe ?
This space for rent. Serious inquiries only please.