开发者

Hyperlinks in xml?

I am writing a small test program that gives the following xml file as output:

<Books>
  <Fiction>
     <Name>Book_Name</Name>
     <P开发者_如何学Pythonrice>price in $</Price>
     <Details>hyperlink to the book's  page</Details>
  </Fiction>
</Books>

I have written this program in C# and write out this xml from LINQ. I want to add hyperlink to the book's page, so that when this xml is viewed in a browser, users can just click on the link to go the respective book's page.

I tried adding <a href="www.somepage.com">click here for details</a>, but this doesn't work. I manually added this line to xml file, I need to know whether i can do something of this sort from LINQ and hyperlink to an external webpage?

Thanks


One approach would be to use an xslt transform to change your xml block into html with links.

Enjoy!


XML is not language of page layout. It doesn't define how element should be presented. HTML does, and you need to convert XML somehow so that browsers can render it to user.


<Books>
  <Fiction>
     <Name>Book_Name</Name>
     <Price>price in $</Price>
     <Details><![CDATA[<a href="www.somepage.com">click here for details</a>]]></Details>
  </Fiction>
</Books>

You can't do it because the text contains characters that are not allowed in direct element content or within attributes. You need to either escape it or use a CDATA section.

How you do this depends on how you are generating the XML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜