Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在不同的XML中使用多个名称空间对XML进行解组或忽略jaxb中的名称空间_Java_Xml_Jaxb_Marshalling_Unmarshalling - Fatal编程技术网

Java 如何在不同的XML中使用多个名称空间对XML进行解组或忽略jaxb中的名称空间

Java 如何在不同的XML中使用多个名称空间对XML进行解组或忽略jaxb中的名称空间,java,xml,jaxb,marshalling,unmarshalling,Java,Xml,Jaxb,Marshalling,Unmarshalling,我有两个XML和相应的Java文件(由trang.jar和xjc工具创建) XML 1: <HSI_ContractDetailModificationRQ xmlns="http://axis.frontend.hsi.hotelbeds.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hotelbeds.com/schemas/2005/06/messag

我有两个XML和相应的Java文件(由trang.jar和xjc工具创建)

XML 1:

<HSI_ContractDetailModificationRQ xmlns="http://axis.frontend.hsi.hotelbeds.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hotelbeds.com/schemas/2005/06/messages/HSI_ContractDetailModificationRQ.xsd">
<Language>CAS</Language>
<Credentials>
    <User>PRUEBASHSI</User>
    <Password>HSI</Password>
</Credentials>
<Contract>
    <Name>TEST HSI</Name>
    <IncomingOffice code="51"/>
    <Sequence>29769</Sequence>
</Contract>
<MinimumStayList>
    <MinimumStay>
        <DateFrom date="20070401"/>
        <DateTo date="20070630"/>
        <MinNumberOfDays>4</MinNumberOfDays>
        <MaxNumberOfDays>12</MaxNumberOfDays>
    </MinimumStay>
</MinimumStayList>
</HSI_ContractDetailModificationRQ>  
* * * *列表中允许以下类型的对象 *{@link MinimumStayModRQ2} * * */ 公共列表getMinimumStay(){ if(minimumStay==null){ minimumStay=新的ArrayList(); } 返回此。最低停留时间; } 公共布尔值isSetMinimumStay(){ 返回((this.minimumStay!=null)&(!this.minimumStay.isEmpty()); } 公众假期最低逗留时间(){ this.minimumStay=null; } } } XML 2:

 HSIContractDetailModificationRQ hsi =  (HSIContractDetailModificationRQ) jaxbUnMarshallerForChannel.unmarshal(new StreamSource(new java.io.StringReader(xmlString)));
如果我解开这个
对于XML 1

 HSIContractInventoryModificationRS  hsi = (HSIContractInventoryModificationRS)   jaxbContextForChannel.createUnmarshaller().unmarshal(new StreamSource(new java.io.StringReader(xmlInventoryRs)));
我得到一个例外:

javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.hotelbeds.com/schemas/2005/06/messages", local:"HSI_ContractInventoryModificationRS"). Expected elements are <{}HSI_ContractDetailModificationRQ>,<{}HSI_ContractDetailModificationRS>,<{}HSI_ContractInventoryModificationRQ>,<{}HSI_ContractInventoryModificationRS>
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647)
JAXBContext jc = JAXBContext.newInstance("com.jmex.model.collada.collada_schema_1_4");
            Unmarshaller u = jc.createUnmarshaller();
            SAXParserFactory parserFactory;
            parserFactory = SAXParserFactory.newInstance();
            parserFactory.setNamespaceAware(false);
            XMLReader reader = parserFactory.newSAXParser().getXMLReader();
            Source er = new SAXSource(reader, new InputSource(sourceStream));
            HSIContractInventoryModificationRS hsi = (HSIContractInventoryModificationRS) u.unmarshal(er);
我得到一个例外:

javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.hotelbeds.com/schemas/2005/06/messages", local:"HSI_ContractInventoryModificationRS"). Expected elements are <{}HSI_ContractDetailModificationRQ>,<{}HSI_ContractDetailModificationRS>,<{}HSI_ContractInventoryModificationRQ>,<{}HSI_ContractInventoryModificationRS>
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647)
JAXBContext jc = JAXBContext.newInstance("com.jmex.model.collada.collada_schema_1_4");
            Unmarshaller u = jc.createUnmarshaller();
            SAXParserFactory parserFactory;
            parserFactory = SAXParserFactory.newInstance();
            parserFactory.setNamespaceAware(false);
            XMLReader reader = parserFactory.newSAXParser().getXMLReader();
            Source er = new SAXSource(reader, new InputSource(sourceStream));
            HSIContractInventoryModificationRS hsi = (HSIContractInventoryModificationRS) u.unmarshal(er);
我已经使用了它,XML1解组器工作正常,但xml2 marshing失败。

请帮助。

我正在与JAXB和XJC一起努力构建绑定来处理名称空间。我花了很多时间在论坛和谷歌上。它不起作用,这让我很生气

至少我在博客中找到了一个忽略名称空间的解决方案。

如果JAXB不考虑xml元素的名称空间,它编写了以下代码,以便在解析时忽略名称空间


它工作正常,JAXB解组成功。(我希望这段代码可以帮助其他人…

您也可以更新您的HSIConventoryModificationrs类吗?
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.hotelbeds.com/schemas/2005/06/messages", local:"HSI_ContractInventoryModificationRS"). Expected elements are <{}HSI_ContractDetailModificationRQ>,<{}HSI_ContractDetailModificationRS>,<{}HSI_ContractInventoryModificationRQ>,<{}HSI_ContractInventoryModificationRS>
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647)
@XmlSchema(namespace = "http://axis.frontend.hsi.hotelbeds.com",    
elementFormDefault  =    
XmlNsForm.QUALIFIED)
  package com.cultagent4.hotelbeds.sa;
 import javax.xml.bind.annotation.*;    
JAXBContext jc = JAXBContext.newInstance("com.jmex.model.collada.collada_schema_1_4");
            Unmarshaller u = jc.createUnmarshaller();
            SAXParserFactory parserFactory;
            parserFactory = SAXParserFactory.newInstance();
            parserFactory.setNamespaceAware(false);
            XMLReader reader = parserFactory.newSAXParser().getXMLReader();
            Source er = new SAXSource(reader, new InputSource(sourceStream));
            HSIContractInventoryModificationRS hsi = (HSIContractInventoryModificationRS) u.unmarshal(er);