<tfoot id='1w7mh'></tfoot>

    1. <small id='1w7mh'></small><noframes id='1w7mh'>

    2. <i id='1w7mh'><tr id='1w7mh'><dt id='1w7mh'><q id='1w7mh'><span id='1w7mh'><b id='1w7mh'><form id='1w7mh'><ins id='1w7mh'></ins><ul id='1w7mh'></ul><sub id='1w7mh'></sub></form><legend id='1w7mh'></legend><bdo id='1w7mh'><pre id='1w7mh'><center id='1w7mh'></center></pre></bdo></b><th id='1w7mh'></th></span></q></dt></tr></i><div id='1w7mh'><tfoot id='1w7mh'></tfoot><dl id='1w7mh'><fieldset id='1w7mh'></fieldset></dl></div>

      <legend id='1w7mh'><style id='1w7mh'><dir id='1w7mh'><q id='1w7mh'></q></dir></style></legend>
      • <bdo id='1w7mh'></bdo><ul id='1w7mh'></ul>
      1. 使用名称空间和前缀解组 JAXB

        JAXB unmarshall with namespaces and prefix(使用名称空间和前缀解组 JAXB)
          <tfoot id='oSivV'></tfoot>
          • <bdo id='oSivV'></bdo><ul id='oSivV'></ul>
              <tbody id='oSivV'></tbody>

              <i id='oSivV'><tr id='oSivV'><dt id='oSivV'><q id='oSivV'><span id='oSivV'><b id='oSivV'><form id='oSivV'><ins id='oSivV'></ins><ul id='oSivV'></ul><sub id='oSivV'></sub></form><legend id='oSivV'></legend><bdo id='oSivV'><pre id='oSivV'><center id='oSivV'></center></pre></bdo></b><th id='oSivV'></th></span></q></dt></tr></i><div id='oSivV'><tfoot id='oSivV'></tfoot><dl id='oSivV'><fieldset id='oSivV'></fieldset></dl></div>
            • <small id='oSivV'></small><noframes id='oSivV'>

                  <legend id='oSivV'><style id='oSivV'><dir id='oSivV'><q id='oSivV'></q></dir></style></legend>

                1. 本文介绍了使用名称空间和前缀解组 JAXB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 JAXB 从 SOAP 响应中解析 xml 元素.我已经为 xml 元素定义了 POJO 类.我已经测试了没有命名空间的 pojo 类,并且前缀它的工作正常.虽然当我尝试使用命名空间和前缀解析时遇到以下异常.要求是解析来自 SOAPMessage 对象的输入

                  I am using JAXB to parse xml elements from the SOAP response. I have defined POJO classes for the xml elements. I have tested pojo classes without namespace and prefix its working fine .Though when i am trying to parse with namespaces and prefix facing the following exception.Requirement is to parse the input from SOAPMessage Object

                  javax.xml.bind.UnmarshalException:意外元素(uri:http://schemas.xmlsoap.org/soap/envelope/",本地:信封").预期的元素是 <{}Envelope>

                  尝试通过为 package-info.java 中的包创建 @XMLSchema 并将此文件定位在包文件夹中来修复.有人可以指导我继续前进吗?

                  Tried to fix by creating @XMLSchema for the package in package-info.java and located this file in package folder.Can any one guide me to move forward?

                  推荐这篇文章但对我没有帮助.

                  Referred this posts but didn help me .

                  已XMLSchema

                  @javax.xml.bind.annotation.XmlSchema (
                      xmlns = {  @javax.xml.bind.annotation.XmlNs(prefix = "env", 
                                   namespaceURI="http://schemas.xmlsoap.org/soap/envelope/"),
                        @javax.xml.bind.annotation.XmlNs(prefix="ns3", namespaceURI="http://www.xxxx.com/ncp/oomr/dto/")
                      }
                    )
                  package com.one.two;
                  

                  提前致谢

                  推荐答案

                  这可以在不使用标准 SOAPMessage 类修改生成的 JAXB 代码的情况下完成.我写了关于这个 here 和 这里

                  This can be done without modifying the generated JAXB code using standard SOAPMessage class. I wrote about this here and here

                  这有点繁琐,但可以正常工作.

                  It's a little fiddly but works correctly.

                  Farm farm = new Farm();
                  farm.getHorse().add(new Horse());
                  farm.getHorse().get(0).setName("glue factory");
                  farm.getHorse().get(0).setHeight(BigInteger.valueOf(123));
                  
                  Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
                  Marshaller marshaller = JAXBContext.newInstance(Farm.class).createMarshaller();
                  marshaller.marshal(farm, document);
                  SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
                  soapMessage.getSOAPBody().addDocument(document);
                  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                  soapMessage.writeTo(outputStream);
                  String output = new String(outputStream.toByteArray());
                  

                  解组

                  String example =
                          "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header /><soapenv:Body><ns2:farm xmlns:ns2="http://adamish.com/example/farm"><horse height="123" name="glue factory"/></ns2:farm></soapenv:Body></soapenv:Envelope>";
                  SOAPMessage message = MessageFactory.newInstance().createMessage(null,
                          new ByteArrayInputStream(example.getBytes()));
                  Unmarshaller unmarshaller = JAXBContext.newInstance(Farm.class).createUnmarshaller();
                  Farm farm = (Farm)unmarshaller.unmarshal(message.getSOAPBody().extractContentAsDocument());
                  

                  这篇关于使用名称空间和前缀解组 JAXB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                  Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                  How to convert Integer to int?(如何将整数转换为整数?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                  Inconsistent behavior on java#39;s ==(java的行为不一致==)
                  Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)

                      <bdo id='VCRgG'></bdo><ul id='VCRgG'></ul>
                      • <tfoot id='VCRgG'></tfoot>
                      • <legend id='VCRgG'><style id='VCRgG'><dir id='VCRgG'><q id='VCRgG'></q></dir></style></legend>
                            <tbody id='VCRgG'></tbody>

                          <small id='VCRgG'></small><noframes id='VCRgG'>

                            <i id='VCRgG'><tr id='VCRgG'><dt id='VCRgG'><q id='VCRgG'><span id='VCRgG'><b id='VCRgG'><form id='VCRgG'><ins id='VCRgG'></ins><ul id='VCRgG'></ul><sub id='VCRgG'></sub></form><legend id='VCRgG'></legend><bdo id='VCRgG'><pre id='VCRgG'><center id='VCRgG'></center></pre></bdo></b><th id='VCRgG'></th></span></q></dt></tr></i><div id='VCRgG'><tfoot id='VCRgG'></tfoot><dl id='VCRgG'><fieldset id='VCRgG'></fieldset></dl></div>