我目前有以下 XML 片段,我正在解析它以读取其值并将它们显示在网页上:
<root>
<PostcardTitle>The Needles</PostcardTitle>
<PostcardDescr>Granite Dells, Prescott</PostcardDescr>
<PostcardImage>
<img alt="GraniteDells" src="GraniteDells.jpg" />
</PostcardImage>
<PostcardDate />
<PostcardCredit>Photo Courtesy of Joe Schmoe</PostcardCredit>
</root>
我正在通过以下代码执行此操作(从数据库中读取片段):
Dim ContentDoc As XDocument
Dim DocPoints As IEnumerable(Of XElement)
ContentDoc = XDocument.Parse(ContentData.Item(0).content)
DocPoints = ContentDoc.<root>.Elements()
For Each Item As XElement In DocPoints
Dim TempLabel As New Label
TempLabel.Text = Item.Name.LocalName & ": " & Item.Value
Dim TempLiteral As New Literal
TempLiteral.Text = "<br/><br/>"
pnlEditItems.Controls.Add(TempLabel)
pnlEditItems.Controls.Add(TempLiteral)
Next
当脚本运行时,所有节点都成功解析并显示,包括空的 PostcardDate 节点,除了 PostcardImage 节点。调试时,评估 Item.Value 返回一个空字符串。但是,评估 Item.ToString() 会返回 PostcardItem 标记和其中的值。
是否需要做一些事情才能让 XElement 对象读取多行值,或者我是否遗漏了其他内容?