Я пытаюсь проанализировать следующий образец xml файла. У меня проблемы с получением текста xrefid = и callout = из файла.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE etm PUBLIC "-//IADS//DTD Patriot Publications (patiads4.dtd)//EN" "patiads4.dtd"[]>
<etm id="n28_1b0n_pc001" label="1">
<chapter label="1">
<title>
INTRODUCTION
</title>
<para0.outline>
<para>
<xref xrefid="n28_1b0n_wp000100" callout="0001 00 General Information" />
</para>
</para0.outline>
<para0.outline>
<para>
<xref xrefid="n28_1b0n_wp000200" callout="0002 00 Nomenclature Cross-Reference" />
</para>
</para0.outline>
<para0.outline>
<para>
<xref xrefid="n28_1b0n_wp000300" callout="0003 00 Differences Between Models" />
</para>
</para0.outline>
<para0.outline>
<para>
<xref xrefid="n28_1b0n_wp000400" callout="0004 00 Equipment Description" />
</para>
</para0.outline>
</chapter>
</etm>
Это код, который я использую:
Imports System.IO
Imports System.Xml
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (ComboBox1.Text = "") Then
MessageBox.Show("No file name entered")
Else
If (System.IO.File.Exists(ComboBox1.Text.ToString())) Then
Dim document As XmlReader = New XmlTextReader(ComboBox1.Text.ToString())
While (document.Read())
Dim type = document.NodeType
If (type = XmlNodeType.Element) Then
If (document.Name = "title") Then
xmlTitle.Visible = True
xmlTitle.Text = document.ReadInnerXml.ToString()
End If
If (document.Name.Contains("para")) Then
Dim test As String = document.ReadInnerXml.ToString()
Dim Doc As New XmlDocument()
Doc.LoadXml("<para>" & test & "</para>")
Dim root As XmlNode = Doc.FirstChild
If root.HasChildNodes Then
Dim _value = root.ChildNodes.Item(0).InnerText.Trim()
xmlRefId1.Visible = True
xmlRefId1.Text = _value
End If
End If
End If
End While
Else
MessageBox.Show("The filename you selected was not found.")
End If
End If
End Sub
End Class