难以将XML字符串解组为由AXIS2/xmlbeans生成的对象。

huangapple go评论77阅读模式
英文:

Difficulty unmarshalling an XML string into an AXIS2/xmlbeans generated object

问题

我目前遇到了一个问题,即将一个XML字符串转换为使用AXIS2和JAXB生成的对象(进行取消编组)。我在使用getter方法访问对象的属性时遇到了问题。奇怪的是,printResult对象的所有getter方法都返回null值。但是,当我调用toString()方法时,会显示具有所有设置值的完整对象。

我对getter方法为什么不返回任何值感到困惑,以及如何使用getter方法检索属性。非常感谢任何帮助或建议。

提前感谢您!

PrintResultType printResult = PrintResultType.Factory.parse(xmlResponse);

PrintDetailsType[] arr = printResult.getPrintDetailsArray();

log.info("arr == null: " + (arr == null) + " arr size: " + arr.length);
// arr == null ? : false arr size 0

BaggageType baggageType = printResult.getBaggageType();
log.info("BaggageType == null: " + (BaggageType == null));
// BaggageType == null : true

log.info(("Unmarshalled printResult:\n" + printResult.toString()));
// 使用所有子对象和数组记录了对象

英文:

I am currently facing an issue with converting an XML string into an object generated with AXIS2 and JAXB (unmarshalling). I'm having trouble accessing the attributes of the object using the getter methods. Strangely, all the getter methods of the printResult object return null values. However, when I invoke the toString() method, the complete object with all the set values is displayed.

I'm perplexed about why the getter methods are not returning any values and how I can retrieve the attributes using the getter methods. Any help or suggestions would be greatly appreciated.

Thank you in advance!

PrintResultType printResult = PrintResultType.Factory.parse(xmlResponse);  

PrintDetailsType[] arr = printResult.getPrintDetailsArray();  

log.info("arr == null: " + (arr == null) + " arr size: " + arr.length);
// arr == null ? : false arr size 0

BaggageType baggageType = printResult.getBaggageType();
log.info("BaggageType == null: " + (BaggageType == null));
// BaggageType == null : true

log.info(("Unmarshalled printResult:\n" + printResult.toString()));
// The object is logged with all subobjects and array

答案1

得分: 0

我发现parse(..)方法只是将XML字符串存储在对象中,但属性没有被设置。

"xmlText()"方法允许检索存储在对象中的字符串,这也是由"toString()"方法输出的。因此,我错误地假设属性在对象中设置了。在解析过程中没有记录任何错误消息,表明这一点。

我修改了输入的XML字符串,为XML字符串中的所有标签添加了必需的XML前缀,现在它可以正常工作。

英文:

I have discovered that the parse(..)-method only stored the XML string in the object, but the attributes were not set.

The "xmlText()" method allows retrieving the string stored in the object, which was also outputted by the "toString()" method. For this reason I wrongly assumed that the attributes were set in the object. No error message is logged during parsing which would indicate this.

I modified the input XML string, adding a required XML prefix to all tags in the XML string, and now it works.

huangapple
  • 本文由 发表于 2023年7月12日 20:58:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76670848.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定