日期:2014-05-18  浏览次数:20789 次

xml文件到底是如何显示的,为什么我双击扩展名是xml的文件显示的却都是带尖括号的代码,而不是象html网页那样的?请看:
文件名:1.xml
文件内容:
<?xml version="1.0" encoding="gb2312" ?> 
- <员工基本数据>
- <个别员工数据>
  <姓名>李劲</姓名> 
  <年龄>30</年龄> 
  <性别>男</性别> 
  <地址>广州市中山路1段10号</地址> 
  <电子邮件>clee@mail.ht.net</电子邮件> 
  <电话>(020)2186206</电话> 
  </个别员工数据>
  </员工基本数据>

显示结果却还是这样子的

------解决方案--------------------
XML文件就是这样的
------解决方案--------------------
xml是元标记语言,与html不同,它只承载数据,类似数据库.
若要它呈现出样式,可与html配合或用xslt和css
------解决方案--------------------
写一个配套的.css文件。例如:
books.xml文件如下:
XML code
 <?xml version="1.0"?> 
<?xml-stylesheet href="Books.css" type="text/css"?>
<books>
<book>
  <title>Beginning ASP.NET </title>
  <ISBM>1-861006-15-2 </ISBM>
  <authors>
<author>Chiris Ullman </author>
<author>Ollie Cornes </author>
<author>John Kauffman </author>
  <author>Rob Birdwell </author>
  </authors>
  <description>ASP.NET is a powerful technology for..... </description>
  <price US="$49.99"/>
</book>
</books>


再写一个books.css,用于控制xml的显示:

CSS code
title 
{
    display:block;
    font-family:Courier New;
    font-size:large;
    font-weight:bold;
    color:Red;
    text-align:center;
}
ISBN
{
    display: block;
    font-family: 宋体;
    font-size: medium;
    font-weight: bold;
    color: Black;
    text-align: left;
}
authors
{
    display: block;
    font-family: 宋体;
    font-size: small;
    font-weight: normal;
    color: Black;
    text-align: left;
}
description
{
    display: block;
    font-family: 宋体;
    font-size: small;
    font-weight: normal;
    color: Black;
    text-align: left;
}