- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的网络服务上,我将变量定义为@XmlAttribute
:
@XmlAttribute
protected String domain;
但是当我通过 SoapUi 进行查询时,它显示为 XML 元素:
<ns:domain>domain</ns:domain>
我在代码中找不到任何错误..
如何解决这个问题?
最佳答案
您在字段上显示注释,但 JAXB 默认使用属性(getter/setter 方法)访问。您是否更改了 JAXB 的默认访问权限?尝试将注释放在 getter 方法上。
编辑:由于您似乎遇到了麻烦,这里有一个可执行示例:
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.*;
import java.io.StringWriter;
public static void main(String[] args) throws Exception {
Foo foo = new Foo("my attribute value", "my element value");
Marshaller marshaller = JAXBContext.newInstance(Foo.class).createMarshaller();
StringWriter stringWriter = new StringWriter();
marshaller.marshal(foo, stringWriter);
System.out.println(stringWriter);
}
@XmlRootElement
static class Foo {
private String anAttribute;
private String anElement;
Foo() {}
public Foo(String anAttribute, String anElement) {
this.anAttribute = anAttribute;
this.anElement = anElement;
}
@XmlAttribute
public String getAnAttribute() { return anAttribute; }
@XmlElement
public String getAnElement() { return anElement; }
}
输出(格式化):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<foo anAttribute="my attribute value">
<anElement>my element value</anElement>
</foo>
关于java - @XmlAttribute 显示为 @XmlElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7192491/
我正在将我的 xml 反序列化为 C# 类。
从 MusicBrainz REST 服务,我得到以下 xml: ... 使用 WCF 和 XmlSerializationFormat,我能够获取类型和 ID 属性...但是如何获取“e
我想在派生类中编码 XMLAttribute,但我遇到了一些问题。 我有 2 个派生类和 1 个父类(super class),如下所示: public class Dog extends Anima
我在以下类(class)中收到以下错误: 无法序列化 DataObjects.Ingredient 类型的成员“成分”。 XmlAttribute/XmlText 不能用于编码复杂类型。 关于为什么的
在我的网络服务上,我将变量定义为@XmlAttribute: @XmlAttribute protected String domain; 但是当我通过 SoapUi 进行查询时,它显示为 XML 元
我在使用 XmlSerializer 生成以下 XML 结构时遇到问题: This is root. Otha. This Is Circ
例如我有一个简单的类 class SomeCfg { [XmlAttribute("ArchivePath")] public string ArchivePath { get; se
我正在尝试使用 javax.xml.bind.annotation 将属性添加到简单类型(在本例中为 String) 所以我想要这个 data 如果 stuff 是 'myObj' 中的字符串,这可能
我想将类 Ticket 序列化为 xml。由于我的自定义字段类,我收到错误:“XmlAttribute/XmlText 不能用于编码复杂类型”。 自定义字段的 xml 应该是这样的(属性数组是 nes
我有很多属性要使用 XmlSerializer 进行序列化。我需要用 [XmlAttribute] 标记每个(简单的)属性,以使输出更短一些。我想知道是否有更简单的方法来做到这一点。有没有办法让它成为
我正在寻找谁来自定义属性的序列化。我以为这会很简单,但我无法按照我想要的方式实现我想做的事情。 所以这是一个简单的例子: 类定义: Class MyClass { [XmlAttribute(
我有一个 XML 文件,它需要一个元素中的 3 个属性。如何按照我的意愿制作街道, zip 和城市属性的顺序? @XmlType(name="Street) @XmlRootElement(nam
我正在制作 SOAP Web 服务以及何时使用 @XmlAttribute(name = "asd:resource") private String asdResource; 我无法在 SoapUI
这个问题已经有答案了: How to change a field name in JSON using Jackson (4 个回答) 已关闭 7 年前。 这似乎是一个奇怪的问题,但这是由于旧版前端
我有一个 XML 文件,它需要在一个元素中有 3 个属性。如何使街道、邮政编码和城市属性的顺序符合我的要求? @XmlType(name="Street) @XmlRootElement(name
有一个带有这样的字段的光环类: private String description; // a lot of text private long price; private int count
我希望能够做这样的事情: //buildArgs XmlNode buildArgs = doc.CreateElement("buildArgs"); XmlAttribute buildAr
我是 JAXB 的新手,在从 XML 到 Java 类实例的转换方面遇到了麻烦。 我有以下 XML: client Greeting 1000 Your Conne
假设我有以下代码,并希望序列化为代码下方的 XML: class Human { [XmlElement("OwnedObjects")] public List ownedObjec
这是我的属性(property): /// /// The Business Unit /// [XmlAttribute("ows_Business_x0020_
我是一名优秀的程序员,十分优秀!