如何使用CSS 显示 XML

浅墨吖_5046

浅墨吖_5046

2020-11-20

3218人浏览

原创

使用CSS显示XML的方法:首先打开相应的代码文件;然后通过“”方法把XML文件链接到CSS文件即可。

推荐:《css视频教程》

使用 CSS 显示 XML

通过使用 CSS,可为 XML 文档添加显示信息。

使用 CSS 显示您的 XML?

使用 CSS 来格式化 XML 文档是有可能的。

下面的例子就是关于如何使用 CSS 样式表来格式化 XML 文档:

CSS
CSS

CSS 官方网站入口。访问 W3C 的 CSS 页面,查看 CSS 标准、学习资料与工作组动态;CSS 是 Web 标准,无需下载安装。

下载

这是 XML 文件:CD 目录

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--  Edited with XML Spy v2007 (http://www.altova.com)  -->
<catalog><cd><title>Empire Burlesque</title>
<artist>Bob Dylan</artist><country>USA</country><company>Columbia</company><price>10.90</price><year>1985</year></cd><cd><title>Hide your heart</title>
<artist>Bonnie Tyler</artist><country>UK</country><company>CBS Records</company><price>9.90</price><year>1988</year></cd><cd><title>Greatest Hits</title>
<artist>Dolly Parton</artist><country>USA</country><company>RCA</company><price>9.90</price><year>1982</year></cd><cd><title>Still got the blues</title>
<artist>Gary Moore</artist><country>UK</country><company>Virgin records</company><price>10.20</price><year>1990</year></cd><cd><title>Eros</title>
<artist>Eros Ramazzotti</artist><country>EU</country><company>BMG</company><price>9.90</price><year>1997</year></cd><cd><title>One night only</title>
<artist>Bee Gees</artist><country>UK</country><company>Polydor</company><price>10.90</price><year>1998</year></cd><cd><title>Sylvias Mother</title>
<artist>Dr.Hook</artist><country>UK</country><company>CBS</company><price>8.10</price><year>1973</year></cd><cd><title>Maggie May</title>
<artist>Rod Stewart</artist><country>UK</country><company>Pickwick</company><price>8.50</price><year>1990</year></cd><cd><title>Romanza</title>
<artist>Andrea Bocelli</artist><country>EU</country><company>Polydor</company><price>10.80</price><year>1996</year></cd><cd><title>When a man loves a woman</title>
<artist>Percy Sledge</artist><country>USA</country><company>Atlantic</company><price>8.70</price><year>1987</year></cd><cd><title>Black angel</title>
<artist>Savage Rose</artist><country>EU</country><company>Mega</company><price>10.90</price><year>1995</year></cd><cd><title>1999 Grammy Nominees</title>
<artist>Many</artist><country>USA</country><company>Grammy</company><price>10.20</price><year>1999</year></cd><cd><title>For the good times</title>
<artist>Kenny Rogers</artist><country>UK</country><company>Mucik Master</company><price>8.70</price><year>1995</year></cd><cd><title>Big Willie style</title>
<artist>Will Smith</artist><country>USA</country><company>Columbia</company><price>9.90</price><year>1997</year></cd><cd><title>Tupelo Honey</title>
<artist>Van Morrison</artist><country>UK</country><company>Polydor</company><price>8.20</price><year>1971</year></cd><cd><title>The very best of</title>
<artist>Cat Stevens</artist><country>UK</country><company>Island</company><price>8.90</price><year>1990</year></cd><cd><title>Stop</title>
<artist>Sam Brown</artist><country>UK</country><company>A and M</company><price>8.90</price><year>1988</year></cd><cd><title>Bridge of Spies</title>
<artist>T'Pau</artist><country>UK</country><company>Siren</company><price>7.90</price><year>1987</year></cd><cd><title>Private Dancer</title>
<artist>Tina Turner</artist><country>UK</country><company>Capitol</company><price>8.90</price><year>1983</year></cd><cd><title>Midt om natten</title>
<artist>Kim Larsen</artist><country>EU</country><company>Medley</company><price>7.80</price><year>1983</year></cd><cd><title>Pavarotti Gala Concert</title>
<artist>Luciano Pavarotti</artist><country>UK</country><company>DECCA</company><price>9.90</price><year>1991</year></cd><cd><title>The dock of the bay</title>
<artist>Otis Redding</artist><country>USA</country><company>Atlantic</company><price>7.90</price><year>1987</year></cd><cd><title>Picture book</title>
<artist>Simply Red</artist><country>EU</country><company>Elektra</company><price>7.20</price><year>1985</year></cd><cd><title>Red</title>
<artist>The Communards</artist><country>UK</country><company>London</company><price>7.80</price><year>1987</year></cd><cd><title>Unchain my heart</title>
<artist>Joe Cocker</artist><country>USA</country><company>EMI</company><price>8.20</price><year>1987</year></cd></catalog>

这是样式表:CSS 文件

CATALOG
{
background-color: #ffffff;
width: 100%;
}
CD
{
display: block;
margin-bottom: 30pt;
margin-left: 0;
}
TITLE
{
color: #FF0000;
font-size: 20pt;
}
ARTIST
{
color: #0000FF;
font-size: 20pt;
}
COUNTRY,PRICE,YEAR,COMPANY
{
display: block;
color: #000000;
margin-left: 20pt;
}

最后,请查看效果:由 CSS 文件格式化的 CD 目录

下面是此XML文件的一个片断。 第二行,css" href="cd_catalog.css"?>,把这个 XML 文件链接到 CSS 文件:

<?xml  version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet  type="text/css" href="cd_catalog.css"?><catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <year>1988</year>
  </cd>
.
.
.
.
</catalog>

注释:使用 CSS 格式化 XML 不是常用的方法,更不能代表 XML 文档样式化的未来。W3C 推荐使用 XSLT。

前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!

相关文章

PHP速学视频免费教程(入门到精通)
PHP速学视频免费教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

相关标签:

css

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
pdf怎么转换成xml格式
pdf怎么转换成xml格式

将 pdf 转换为 xml 的方法:1. 使用在线转换器;2. 使用桌面软件(如 adobe acrobat、itext);3. 使用命令行工具(如 pdftoxml)。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

2024.04.01

5204

5

xml怎么变成word
xml怎么变成word

步骤:1. 导入 xml 文件;2. 选择 xml 结构;3. 映射 xml 元素到 word 元素;4. 生成 word 文档。提示:确保 xml 文件结构良好,并预览 word 文档以验证转换是否成功。想了解更多xml的相关内容,可以阅读本专题下面的文章。

2024.08.01

6777

7

xml是什么格式的文件
xml是什么格式的文件

xml是一种纯文本格式的文件。xml指的是可扩展标记语言,标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言。想了解更多相关的内容,可阅读本专题下面的相关文章。

2024.11.28

2662

7

Go-Zero API开发使用教程
Go-Zero API开发使用教程

本专题聚焦Go-Zero的API开发,拆解.api描述文件的语法结构、路由与分组定义、参数绑定与校验规则,说明统一响应体、JWT鉴权、跨域与接口文档生成的落地方式,并给出网关聚合与接口测试的实践建议。

2026.11.12

140

15

Go-Zero安装与goctl环境配置教程
Go-Zero安装与goctl环境配置教程

本专题围绕Go-Zero的安装与工具链配置展开,讲清Go版本要求、goctl安装方式、代理镜像、protoc依赖与环境变量设置,说明多版本共存、升级回退与CI流水线安装的做法,并整理安装阶段的常见报错与验证步骤。

2026.11.12

100

15

Go-Zero零基础入门教程
Go-Zero零基础入门教程

本专题整理Go-Zero的入门知识,从框架定位、环境准备到跑通第一个API服务,讲清目录分层、配置加载、日志与中间件的基本用法,并对比Gin、Kratos的差异,帮助Go开发者建立整体认知,判断它是否适合当前项目。

2026.11.12

80

15

Postman身份认证怎么配置
Postman身份认证怎么配置

本专题从实际API接口调试场景出发,讲解Postman身份认证的完整配置流程,包括常见认证协议介绍、授权参数设置、访问令牌填写、OAuth 2.0授权及认证失败排查,帮助用户正确完成接口授权与访问验证。

2026.11.06

160

12

Postman请求头Headers怎么设置
Postman请求头Headers怎么设置

围绕Postman HTTP请求头配置展开,讲解Headers选项的具体使用方式,包括Key和Value参数填写、请求头信息添加、常见Header字段设置及请求头修改方法,帮助用户解决接口调试过程中遇到的请求头配置问题。

2026.11.06

140

13

Postman接口请求发送教程
Postman接口请求发送教程

详细介绍Postman接口请求的创建与发送方法,涵盖GET和POST请求、URL配置、请求参数、Headers请求头、Body请求体设置以及响应结果查看,帮助用户掌握Postman接口请求的完整操作流程。

2026.11.06

120

10

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程