英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论