java xml 子节点_java-使用JAXB获取子节点中存在的XML数据作为...

更新

根据您的评论:

Hi.. Thanks for your reply.. @Blaise

Doughan & @CoolBeans in the above

example you provide you have mentioned

String Value but in my

xml, instead of “String Value” there

will be another XML inside it. like

Richard

and I need the

“Richard” as

string in the output. Please let me

know still you want more information.

Thanks.. Cheers, Sakthi. S

您可以结合使用@XmlAnyElement和DomHandler实现来处理此用例.有关详细示例,请参见:

更新#2

根据您的评论

Can you please tell me what is change

need to be done in the schema to make

that filed “@XmlAnyElement”, since I

am generating the java classes on the

build time.

您可以使用JAXB dom模式注释来导致在属性上生成XmlAnyElement:

XJC电话

xjc -d out -b bindings.xml dom.xsd

dom.xsd

xmlns:xs="http://www.w3.org/2001/XMLSchema"

xmlns="http://www.example.com/default"

targetNamespace="http://www.example.com/default">

bindings.xml

xmlns:xs="http://www.w3.org/2001/XMLSchema"

xmlns:jxb="http://java.sun.com/xml/ns/jaxb"

version="2.1">

顾客

客户的地址属性将使用@XmlAnyElement进行注释:

package com.example._default;

import javax.xml.bind.annotation.XmlAccessType;

import javax.xml.bind.annotation.XmlAccessorType;

import javax.xml.bind.annotation.XmlAnyElement;

import javax.xml.bind.annotation.XmlRootElement;

import javax.xml.bind.annotation.XmlType;

import org.w3c.dom.Element;

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "", propOrder = {

"address"

})

@XmlRootElement(name = "customer")

public class Customer {

@XmlAnyElement

protected Element address;

public Element getAddress() {

return address;

}

public void setAddress(Element value) {

this.address = value;

}

}

原始答案

您可能正在寻找@XmlValue批注.例如,如果您有以下课程:

@XmlRootElement

@XmlAccessorType(XmlAccessType.FIELD

public class Child {

@XmlValue

private String value;

}

上等人将编组为:

String Value

在相应的XML模式中,子元素的类型为xs:string.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值