代码之家  ›  专栏  ›  技术社区  ›  Dillie-O

XElement.Value不读取多行数据

  •  0
  • Dillie-O  · 技术社区  · 14 年前

    我当前正在解析以下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
    

    要让XElement对象读取多行值,是否需要执行某些操作,或者我是否遗漏了其他操作?

    1 回复  |  直到 14 年前
        1
  •  2
  •   Jon Skeet    14 年前

    你错过了什么 XElement.Value 记录返回:

    包含所有文本的字符串 连接。

    PostcardImage 文档不存在 alt img 标记)并使用它。或者,如果您只想逐字嵌入XML,您可能只需要调用 Nodes() 在元素上。。。我不 认为 DOM的“InnerXml”属性有任何等价物。