gpt4 book ai didi

html - 在 XML 文档中嵌入 HTML anchor

转载 作者:太空宇宙 更新时间:2023-11-04 15:42:20 25 4
gpt4 key购买 nike

我将如何在 xml 元素中嵌入 html anchor ?考虑以下 xml:

<?xml version="1.0" encoding="utf-8"?>
<Customers>
<Customer>
<FirstName>Joe</FirstName>
<LastName>Mama</LastName>
<Email><a href="mailto:joemama@gmail.com">joemama@gmail.com</a></Email>
<Website><a href="http://www.joemama.com">www.joemama.com</a></Website>
</Customer>
</Customer>

当我显示元素内容时,我只得到文本,没有超链接。

这是我用来在 asp.net web 表单页面中显示 xml 数据的代码:

客户 View HTML

<%@ control language="vb" autoeventwireup="false" codebehind="CustomerView.ascx.vb"
inherits="Sparta.Web.CustomerView" %>
<div class="View">
<table>
<tr>
<td>First Name:</td>
<td><asp:label id="FirstName" runat="server"></asp:label></td>
</tr>
<tr>
<td>Last Name:</td>
<td><asp:label id="LastName" runat="server"></asp:label></td>
</tr>
<tr>
<td>Email:</td>
<td><asp:literal id="Email" runat="server"></asp:literal></td>
</tr>
<tr>
<td>Website:</td>
<td><asp:literal id="Website" runat="server"></asp:literal></td>
</tr>
</table>
</div>

CustomerView 代码隐藏

Public Partial Class CustomerView
Inherits System.Web.UI.UserControl

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.DataBind()
End Sub

Private Sub DataBind()

Dim xmlDoc As System.Xml.Linq.XDocument = Nothing
xmlDoc = XDocument.Load(Server.MapPath("~/data/CustomerData.xml"))

Dim listQuery = _
From list In xmlDoc.Descendants("Customer") _
Where list.Element("LastName").Value = Request.QueryString("id") _
Select _
FirstName = list.Element("FirstName").Value, _
LastName= list.Element("LastName").Value, _
Email = list.Element("Email").Value, _
Website = list.Element("Website").Value

Dim listInfo = listQuery(0)
If listInfo Is Nothing Then
Throw New ApplicationException("Missing CustomerData Element")
End If

Me.FirstName.Text = listInfo.FirstName
Me.LastName.Text = listInfo.LastName
Me.Email.Text = listInfo.Email
Me.Website.Text = listInfo.Website

End Sub

End Class

最佳答案

XML就是XML,HTML就是HTML。如果您尝试将 XML 解析为 HTML,则提取 <Email> 的内容,我建议用 <![CDATA[ 包裹起来和 ]]>并用 HTML 输出。

另请提供您用于显示此内容的代码。

关于html - 在 XML 文档中嵌入 HTML anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1604452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com