使用css显示xml
看一个demo.xml
<?xml version="1.0" encoding="gbk"?> <?xml-stylesheet type="text/css" href="demo.css" ?> <information> <man> <name>爱迪生</name> <id>1</id> <email>cheng@qq.com</email> <phone>123445</phone> </man> </information>
demo.css
name{ display:block; font-size:20pt; font-weight:blod; } id,email,phone{ display:block; font-size:15pt; font-weight:normal; font-style:italic; }
显示的结果为:
注意display:block;显示时当成一个块,会换行显示
再看一个例子,cd.xml
<?xml version="1.0" encoding="gbk"?> <?xml-stylesheet type="text/css" href="cd.css"?> <Catalog> <Cd> <Title>empire burlesque</Title> <Artist>bob Dylan</Artist> <Price>10.9</Price> <Year>1990</Year> </Cd> <Cd> <Title>empire burlesque</Title> <Artist>bob Dylan</Artist> <Price>10.9</Price> <Year>1990</Year> </Cd> <Cd> <Title>empire burlesque</Title> <Artist>bob Dylan</Artist> <Price>10.9</Price> <Year>1990</Year> </Cd> <Catalog>
cd.css
Catalog{ background-color:#ffaeff; width:100%; } Cd{ display:block; margin-bottom:10pt; } Title,Artist{ color:#ff0000; font-size:20pt; } Price,Year{ display:block; color:#ff00aa; font-size:20pt; }
效果为:
使用XSLT显示xml
XSLT是首选的xml样式表语言
XSLT (eXtensible Stylesheet Language Transformations) 远比 CSS 更加完善。
原文链接:https://www.f2er.com/xml/300072.html