简体   繁体   English

从XmlBeans XmlObject到String的所有元素

[英]All Elements from a XmlBeans XmlObject to String

Is is possible to return all elements of an XMLBeans XMLObject even if they were not set? 是否可以返回XMLBeans XMLObject的所有元素(即使未设置)? I have a XmlObject that I generated from an XSD and when I convert the XmlObject to a String I would like to return ALL fields, not just the few that I've set. 我有一个从XSD生成的XmlObject,当我将XmlObject转换为String时,我想返回所有字段,而不仅仅是返回我设置的几个字段。 I tried the following command: 我尝试了以下命令:

xmlObject.toString();
xmlObject.xmlText();
xmlObject.save(stringWriter); // Then converted the StringWriter to a String

All of the above commands only return the fields I have actually set a value for. 以上所有命令仅返回我实际上为其设置值的字段。 If there isn't a command to do this is there an attribute that I can add to the XSD to make the field required? 如果没有命令可以执行此操作,那么是否可以将属性添加到XSD中以使该字段为必填字段? I already have minOccurs="1" . 我已经有minOccurs="1"

我猜想,您必须在架构定义中为所有(强制性)属性指定默认值,以便在XmlObject的字符串输出中隐式设置它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM