在带有 JDK 1.6 的 Glassfish 2.1 上使用 XMLBeans 解组对象为 null

发布于 2024-11-15 00:37:34 字数 5037 浏览 6 评论 0原文

我使用带有 XMLBeans 绑定的 XJC Maven 插件从 WSDL + XSD 生成代码。该代码部署在在 JDK 1.6 上运行的 Glassfish 2.1.1 上,

我尝试使用生成的对象解析 XML 字符串。对象解析很好,没有错误,但是当我在对象上调用 getXXX() 方法时,它们都是 null。

我一直在寻找和寻找一些有关如何修复它的提示,但没有成功。

任何帮助将不胜感激。

正在解析的 XML:


<ccs:printAdReturn xmlns:ccs="http://www.huntingtonmast.com/ccssAdInfo">
    <ccs:adPrice>244.0</ccs:adPrice>
    <ccs:sap-order-request>
        <sap-order-request xmlns="http://huntmast/pas">
            <business-partner xmlns="">2010011755</business-partner>
            <source-system xmlns="">05</source-system>
            <authorizer-name xmlns="">Unknown user</authorizer-name>
            <item-ad xmlns="">
                <booking-unit>JOBSFRZ</booking-unit>
                <content-component>905</content-component>
                <promo-code />
                <price-group>JB</price-group>
                <non-package>
                    <ad-schedule>
                        <publication-date>2009-09-26-04:00</publication-date>
                        <basic-booking-unit>JOBSFRZ</basic-booking-unit>
                    </ad-schedule>
                    <ad-schedule>
                        <publication-date>2009-09-27-04:00</publication-date>
                        <basic-booking-unit>JOBSFRZ</basic-booking-unit>
                    </ad-schedule>
                </non-package>
                <ad-content>
                    <template-id>CCSS_JOBS3_B</template-id>
                    <proof-required>false</proof-required>
                    <panel-field>
                        <field-name>JOB-TITLE</field-name>
                        <field-value>
                            <![CDATA[TECHS NEEDED!]]>
                        </field-value>
                    </panel-field>
                    <panel-field>
                        <field-name>KEYWORD</field-name>
                        <field-value>
                            <![CDATA[HVAC]]>
                        </field-value>
                    </panel-field>
                    <panel-field>
                        <field-name>CCSS-SIG2</field-name>
                        <field-value />
                    </panel-field>
                    <panel-field>
                        <field-name>J-FONT1</field-name>
                        <field-value>
                            <![CDATA[08]]>
                        </field-value>
                    </panel-field>
                    <panel-field>
                        <field-name>CCSS-SIG1</field-name>
                        <field-value />
                    </panel-field>
                    <panel-field>
                        <field-name>CCSS-ADTEXT1</field-name>
                        <field-value>
                            <![CDATA[Hello World, How are you ?]]>
                        </field-value>
                    </panel-field>
                </ad-content>
            </item-ad>
        </sap-order-request>
    </ccs:sap-order-request>
    <ccs:numberLines>8</ccs:numberLines>
</ccs:printAdReturn>

用于解析的 Java 代码

            oPrintResponse.setStatus(SUCCESS_CODE);
            oPrintResponse.setStatusMessage(STATUS_SUCCESS);

            XmlOptions validateOptions = new XmlOptions();
            validateOptions.setCharacterEncoding("utf-8");
            validateOptions.setValidateOnSet();
            ArrayList errorList = new ArrayList(); 
            validateOptions.setErrorListener(errorList); 

            PrintAdReturnDocument oAdReturnDocument = PrintAdReturnDocument.Factory.parse(pXml,validateOptions);

            oPrintResponse.setStatus(SUCCESS_CODE);
            oPrintResponse.setStatusMessage(STATUS_SUCCESS);

            XmlOptions validateOptions = new XmlOptions();
            validateOptions.setCharacterEncoding(cd.getSysAdmin(CCSS_XML_CHARACTER_ENCODING));
            validateOptions.setValidateOnSet();
            ArrayList errorList = new ArrayList(); 
            validateOptions.setErrorListener(errorList); 

            PrintAdReturnDocument oAdReturnDocument = PrintAdReturnDocument.Factory.parse(pXml,validateOptions);

                    if(oPrintAdReturn == null)
            {
                log.warn("getPrintAdReturn - oPrintAdReturn is null");
                return null;
            }
            CCSSPrint oCCSSPrint = new CCSSPrint();
            oCCSSPrint.setPrice(oPrintAdReturn.getAdPrice());

oPrintAdReturn.getAdPrice() 始终返回 0.0,任何其他 getter 返回 null。

I am using XJC Maven plugin with XMLBeans binding to generate code from WSDL + XSD. The code is deployed on Glassfish 2.1.1 running on JDK 1.6

I am trying to parse a XML String using the generated objects. The object parsing is fine without errors but when I call the getXXX() methods on the object, they are all null.

I have been scouting and hunting for some hints on how to fix it but without avail.

Any help will be appreciated.

The XML that is being parsed:


<ccs:printAdReturn xmlns:ccs="http://www.huntingtonmast.com/ccssAdInfo">
    <ccs:adPrice>244.0</ccs:adPrice>
    <ccs:sap-order-request>
        <sap-order-request xmlns="http://huntmast/pas">
            <business-partner xmlns="">2010011755</business-partner>
            <source-system xmlns="">05</source-system>
            <authorizer-name xmlns="">Unknown user</authorizer-name>
            <item-ad xmlns="">
                <booking-unit>JOBSFRZ</booking-unit>
                <content-component>905</content-component>
                <promo-code />
                <price-group>JB</price-group>
                <non-package>
                    <ad-schedule>
                        <publication-date>2009-09-26-04:00</publication-date>
                        <basic-booking-unit>JOBSFRZ</basic-booking-unit>
                    </ad-schedule>
                    <ad-schedule>
                        <publication-date>2009-09-27-04:00</publication-date>
                        <basic-booking-unit>JOBSFRZ</basic-booking-unit>
                    </ad-schedule>
                </non-package>
                <ad-content>
                    <template-id>CCSS_JOBS3_B</template-id>
                    <proof-required>false</proof-required>
                    <panel-field>
                        <field-name>JOB-TITLE</field-name>
                        <field-value>
                            <![CDATA[TECHS NEEDED!]]>
                        </field-value>
                    </panel-field>
                    <panel-field>
                        <field-name>KEYWORD</field-name>
                        <field-value>
                            <![CDATA[HVAC]]>
                        </field-value>
                    </panel-field>
                    <panel-field>
                        <field-name>CCSS-SIG2</field-name>
                        <field-value />
                    </panel-field>
                    <panel-field>
                        <field-name>J-FONT1</field-name>
                        <field-value>
                            <![CDATA[08]]>
                        </field-value>
                    </panel-field>
                    <panel-field>
                        <field-name>CCSS-SIG1</field-name>
                        <field-value />
                    </panel-field>
                    <panel-field>
                        <field-name>CCSS-ADTEXT1</field-name>
                        <field-value>
                            <![CDATA[Hello World, How are you ?]]>
                        </field-value>
                    </panel-field>
                </ad-content>
            </item-ad>
        </sap-order-request>
    </ccs:sap-order-request>
    <ccs:numberLines>8</ccs:numberLines>
</ccs:printAdReturn>

The Java Code for Parsing

            oPrintResponse.setStatus(SUCCESS_CODE);
            oPrintResponse.setStatusMessage(STATUS_SUCCESS);

            XmlOptions validateOptions = new XmlOptions();
            validateOptions.setCharacterEncoding("utf-8");
            validateOptions.setValidateOnSet();
            ArrayList errorList = new ArrayList(); 
            validateOptions.setErrorListener(errorList); 

            PrintAdReturnDocument oAdReturnDocument = PrintAdReturnDocument.Factory.parse(pXml,validateOptions);

            oPrintResponse.setStatus(SUCCESS_CODE);
            oPrintResponse.setStatusMessage(STATUS_SUCCESS);

            XmlOptions validateOptions = new XmlOptions();
            validateOptions.setCharacterEncoding(cd.getSysAdmin(CCSS_XML_CHARACTER_ENCODING));
            validateOptions.setValidateOnSet();
            ArrayList errorList = new ArrayList(); 
            validateOptions.setErrorListener(errorList); 

            PrintAdReturnDocument oAdReturnDocument = PrintAdReturnDocument.Factory.parse(pXml,validateOptions);

                    if(oPrintAdReturn == null)
            {
                log.warn("getPrintAdReturn - oPrintAdReturn is null");
                return null;
            }
            CCSSPrint oCCSSPrint = new CCSSPrint();
            oCCSSPrint.setPrice(oPrintAdReturn.getAdPrice());

The oPrintAdReturn.getAdPrice() always returns 0.0, and any other getters return null.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文