首页 \ 问答 \ JAXB:具有文本内容和属性的元素,使用XJC生成类(JAXB: an element with textual content and attributes, generating classes with XJC)

JAXB:具有文本内容和属性的元素,使用XJC生成类(JAXB: an element with textual content and attributes, generating classes with XJC)

最近我遇到了一个似乎很常见的问题:如何用属性和简单的文本内容来表示XML元素,如下所示:

<elem attr="aval">elemval</elem>

使用JAXB。

我已经找到了许多关于如何执行此操作的建议,但这些建议中的每一个都涉及手动编辑绑定类。

我有一组模式,我使用XJC将这些模式转换为Java类。 但是,它似乎产生错误的代码,即它不生成设置普通内容的方法,只有设置属性的方法。

是否有可能解决XJC的这种行为? 广泛的谷歌搜索对这个问题没有帮助。


Recently I have faced a problem which seems to be very common: how to represent an XML element with attributes and simple textual content, like this:

<elem attr="aval">elemval</elem>

using JAXB.

I've found many advices on how to do this, but every one of these advices involves manual editing of binding classes.

I have a set of schemas and I use XJC to convert these schemas to Java classes. However, it seems that it produces wrong code, i.e. it does not generate methods to set plain content, there are methods for setting attributes only.

Is it possible to fix this behavior of XJC? Extensive googling didn't help on this question.


原文:https://stackoverflow.com/questions/12859885
更新时间:2022-05-20 13:05

最满意答案

这不是一个观点的界限。 视图边界表示类型参数A是有界的,因为它可以作为类型B查看(转换为)。 你有什么倒置的类型和类型参数,所以它没有资格。

为了使事情更清楚, 绑定是对“自由”类型的限制 - 类型参数。 例如:

type A <: String // A has an upper bound
type A >: String // A has a lower bound

所以观点界限也是一个限制 - 一个通过非常不同的机制强加的界限。 因此,它只能强加在类型参数上,而不能强加在类型上。

当然,说String => A必须存在也是一种界限,但不是一个有名称或语法糖的人。


That is not a view bound. A view bound says that a type parameter A is bounded in that it can be viewed (converted to) as a type B. What you have inverted type and type parameter, so it doesn't qualify.

To make things more clear, a bound is a limit on a "free" type -- a type parameter. For example:

type A <: String // A has an upper bound
type A >: String // A has a lower bound

So a view bound is also a limit -- one imposed through a very different mechanism. As such, it can only be imposed on a type parameter, not on a type.

Surely, saying String => A must exist is also a kind of bound, but not one that has a name or syntactic sugar for.

相关问答

更多
  • 那么,我发现错误: tf.layers.Conv1D!= tf.layers.conv1d 。 将前者更改为后者消除了错误。 让TensorFlow / Python用户当心! 尽管TensorFlow似乎避免了Python的对象模型(考虑到分布式,低级计算的可能性,这可能是必要的),但实际上在Python API中有一些真正的类。 类构造函数可以接受许多(全部?)与相同名称的便利函数相同的参数。 Well, I found the error: tf.layers.Conv1D != tf.layers. ...
  • 没有许可证,很难在线查找该版本的文档。 您可以通过输入查找您的版本的文档 help conv 据推测,你的版本后界面发生了变化。 所以你必须看看你的文档说什么。 FWIW,文件档案在这里 ,但我无法访问它们。 另外,我在Matlab 2015b中尝试了你的代码(也就是b ,而不是a ),并且它工作正常。 所以它必须在这两个版本之间改变。 根据excaza,文档没有改变。 所以,就像他们说的那样,它一定是一个阴影问题。 您可以通过在代码片段之前使用clear all来验证。 It is hard to fi ...
  • 这不是一个观点的界限。 视图边界表示类型参数A是有界的,因为它可以作为类型B查看(转换为)。 你有什么倒置的类型和类型参数,所以它没有资格。 为了使事情更清楚, 绑定是对“自由”类型的限制 - 类型参数。 例如: type A <: String // A has an upper bound type A >: String // A has a lower bound 所以观点界限也是一个限制 - 一个通过非常不同的机制强加的界限。 因此,它只能强加在类型参数上,而不能强加在类型上。 当然,说Stri ...
  • 给定: scala> def max[T <% Ordered[T]](xs: List[T]) = xs.max max: [T](xs: List[T])(implicit evidence$1: T => Ordered[T])T scala> case class Pair(x: String, y: Double) defined class Pair 您需要为Pair定义排序对象: scala> implicit val order = scala.math.Ordering.by[Pair ...
  • 是的,必须用零填充输入以克服小输入图像大小问题。 要计算每个级别的输出要素图,请使用以下公式: H_out = ( H_in + 2 x Padding_Height - Kernel_Height ) / Stride_Height + 1 W_out = (W_in + 2 x Padding_Width - Kernel_Width) / Stride_Width + 1 您可以按照上面的公式保持填充。 Yes, the input must be padded with zeros to over ...
  • 将参数类型参数A添加到Subnamer (在Subnamer继承中)对我Subnamer (Scala版本2.10.7): class SubNamer[A <% Nameish](e: Class[A]) extends Namer[A](e) 顺便说一句,没有修改的示例仅适用于Scala版本2.11.5。 希望这可以帮助。 Adding parameter type parameter A to Namer (in the Subnamer inheritance) worked for me (Sc ...
  • 排除卷积中的坏点很容易。 如果M2包含您要包含的像素为1 ,而对于那些不包含的像素包含0 ,那么您只需执行以下操作: newImage = conv2(A.*M2, M1,'same'); 这可能足以满足您的需要,但您必须确定“平均”的确切含义。例如,给定您的内核ones(10) ,最后您可能需要执行以下操作: npts = conv2(ones(size(A)).*M2, M1, 'same') newImage = newImage./npts 即,将每个像素除以实际包含在该像素的卷积中的像素数。 ...
  • 这是一个错误,即SI-10405 ,我前段时间开了。 出于某种原因, Predef导致隐式搜索失败。 如果使用-Yno-predef标志编译代码,则会成功。 症状是你在-Xlog-implicits下编译时看到Predef.conforms[A]试图解析隐式的Predef.conforms[A] : λ scalac -Xlog-implicits Bar.scala Bar.scala:16: listImplicitConversion is not a valid implicit value for ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。