1

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

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

我一直在寻找和寻找有关如何修复它的一些提示,但无济于事。

任何帮助将不胜感激。

正在解析的 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。

4

0 回答 0