XML样式

今天写了一个简单的XML,丢到浏览器中时有这样的提示:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

这是“XML样式”的问题。

可以有两种方式定义XML的样式:CSS和XSLT。

CSS的例子如下:

test.xml

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/css" href="test.css"?> 
<test>
<name>OldWang</name>
<sex>male</sex>
<birthday>8.22</birthday>
<skill>AI</skill>
</test>

test.css

resume{ display: block;}
name{ display: block; font-size:120%;}
sex{ display:block; text-indent:2em}
birthday{ display:block; text-indent:2em}
skill{ display:block; text-indent:2em}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring项目中,我们可以通过使用Spring Web Services框架来创建Web服务。在返回指定XML样式数据方面,我们可以使用Spring的消息转换器(Message Converters)来实现。 以下是一个示例代码,演示如何使用Spring Web Services框架和消息转换器来返回XML格式的数据: ```java import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class MyWebService { @RequestMapping(value = "/my-webservice", produces = MediaType.APPLICATION_XML_VALUE) @ResponseBody public MyResponseObject myWebServiceMethod() { MyResponseObject response = new MyResponseObject(); // populate response object return response; } } ``` 在上面的示例代码中,我们使用 @RequestMapping 注解来映射一个Web服务方法。我们指定了 produces 参数来指定响应的内容类型为 XML。我们还使用 @ResponseBody 注解来指示Spring将返回值转换为XML格式并作为响应体发送。 需要注意的是,要使用消息转换器,需要在Spring的配置文件中添加以下配置: ```xml <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter"> <property name="supportedMediaTypes" value="application/xml" /> </bean> </list> </property> </bean> ``` 在上面的配置中,我们添加了一个用于转换XML格式的消息转换器。这个转换器将会被RequestMappingHandlerAdapter自动识别,并用于将响应转换为XML格式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值