Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.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 REST web服务如何使用复杂的XML_Java_Rest_Xml Parsing_Jaxb - Fatal编程技术网

Java REST web服务如何使用复杂的XML

Java REST web服务如何使用复杂的XML,java,rest,xml-parsing,jaxb,Java,Rest,Xml Parsing,Jaxb,我们可以使用JAXB将XSD转换为Java对象。如果XML有多个元素,它将从中创建多个类。JAXB为以下XML创建了多个类: <cXML payloadID="dfbgw859yjdfngoho9gj" timestamp="12/12/2012 4:51:22 PM" xml:lang=" en-us "> <Header> <From> <Credential domain="web"> <Identity>UAT Mast

我们可以使用JAXB将XSD转换为Java对象。如果XML有多个元素,它将从中创建多个类。JAXB为以下XML创建了多个类:

    <cXML payloadID="dfbgw859yjdfngoho9gj" timestamp="12/12/2012 4:51:22 PM" xml:lang=" en-us ">
<Header>
<From>
<Credential domain="web">
<Identity>UAT Master</Identity>
</Credential>
</From>
<To>
<Credential domain="web">
<Identity>notused</Identity>
</Credential>
</To>
<Sender>
<Credential domain="web">
<Identity>notused</Identity>
</Credential>
</Sender>
</Header>
<Request>
<OrderRequest>
<OrderRequestHeader orderDate="12/12/2012 4:51:22 PM" type="new">
<ID domain="Web">645</ID>
<Total>
<Money currency="USD">129.48</Money>
</Total>
<Shipping>
<Money currency="USD">12.57</Money>
<Description xml:lang="en-US"/>
</Shipping>
<Tax>
<Money currency="USD">8.91</Money>
</Tax>
<Extrinsic name="Additional Comments or Instructions:"/>
<BillTo>
<Address contactId="210306">
<CompanyName>UAT Master</CompanyName>
<ContactId domain="Web">210306</ContactId>
<PaymentType>CREDITCARD</PaymentType>
<PostalAddress name="default">
<FirstName>test</FirstName>
<LastName>test</LastName>
<Street>9050 Malabar Hills</Street>
<City>Newark</City>
<State>NJ</State>
<Country isoCountryCode="USA">USA</Country>
<PostalCode>40485</PostalCode>
<Email>test@test.com</Email>
<WorkPhone>2342423434</WorkPhone>
</PostalAddress>
</Address>
</BillTo>
<Extrinsic name="Purchase Order Number:"/>
<Contact Role="buyer">
<ID domain="Web">testName</ID>
<Name>testName M</Name>
<Email>testName.testLastName@test.com</Email>
<Company>UAT Master</Company>
<Department/>
</Contact>
</OrderRequestHeader>
<ItemOut quantity="120" lineNumber="1">
<Type>PRINT</Type>
<ItemId domain="Web">210300</ItemId>
<StatusType>APPROVED</StatusType>
<PostageAmount currency="USD">0.00</PostageAmount>
<Discount currency="USD">0.00</Discount>
<orderItemName>cxml test for cc payment</orderItemName>
<orderItemDescription>test cxml only with cc payment</orderItemDescription>
<Price>108.00</Price>
<ItemID>
<SupplierPartID>BUSCRD001</SupplierPartID>
<SupplierPartAuxiliaryID/>
</ItemID>
<ItemDetail>
<URL>
http://127.0.1.1/Agggf/NgA=/Mfsdfsf==/2012/3/28/dfafDYAMgA1AA==.jpg
</URL>
<Description xml:lang="en-US">Business Card</Description>
<UnitPrice>
<Money currency="USD">0.90</Money>
</UnitPrice>
<UnitOfMeasure>PER_PIECE</UnitOfMeasure>
<Extrinsic name="options">
<ul>
<li>
Color/Yellow=
<span>0.00</span>
</li>
<li>
Paper Type/Gloss=
<span>0.00</span>
</li>
</ul>
</Extrinsic>
<Classification domain=""/>
<ManufacturerPartID/>
<ManufacturerName xml:lang="en-US"/>
</ItemDetail>
<ShipTo>
<Address contactId="210301">
<ContactId domain="Web">210301</ContactId>
<CompanyName>UAT Master</CompanyName>
<PostalAddress name="default">
<FirstName>test</FirstName>
<LastName>test</LastName>
<Street>9050 Great Hills</Street>
<City>Newark</City>
<State>New Jersey</State>
<Country isoCountryCode="USA">USA</Country>
<PostalCode>78759</PostalCode>
<Email>testName.testLastName@test.com</Email>
<WorkPhone>2342423434</WorkPhone>
</PostalAddress>
</Address>
</ShipTo>
<Shipping>
<Money currency="USD">12.57</Money>
<Description xml:lang="en-US">USPS Ground</Description>
</Shipping>
<Distribution>
<Accounting name="DistributionCharge">
<AccountingSegment id="">
<Name xml:lang="en-US"/>
<Description xml:lang="en-US"/>
</AccountingSegment>
<AccountingSegment id="">
<Name xml:lang="en-US"/>
<Description xml:lang="en-US"/>
</AccountingSegment>
</Accounting>
<Charge>
<Money currency="USD"/>
</Charge>
</Distribution>
<Distribution>
<Accounting name="DistributionCharge">
<AccountingSegment id="">
<Name xml:lang="en-US"/>
<Description xml:lang="en-US"/>
</AccountingSegment>
<AccountingSegment id="">
<Name xml:lang="en-US"/>
<Description xml:lang="en-US"/>
</AccountingSegment>
</Accounting>
<Charge>
<Money currency="USD"/>
</Charge>
</Distribution>
<Comments xml:lang="en-US"/>
</ItemOut>
</OrderRequest>
</Request>
</cXML>

可能是为
cXML
标记创建的类。您有这样的类吗?这些是JAXB为上述XML创建的类:AccountingSegmentType AccountingType AddressType BillToType CXMLType ChargeType ClassificationType CommentType ContactId类型ContactType CountryType CredentialType DescriptionType折扣类型DistributionType ExterinsicType FromType HeaderType IDType ItemDetailTypeItemIDType ItemOutType LiType ManufacturerNameType MoneyType NameType ObjectFactory OrderRequestHeaderType OrderRequestType PostageAmountType PostalAddressType RequestType SenderType ShipToType ShippingType TaxType ToType TotalType UlType UnitPriceType Try
CXMLType
@POST
    @Path("/XMLTest")
    @Consumes("application/xml")
    public Response consumeXML(**WhichObjectToAcceptHere whichObject**) {

        String output = objectFactory.toString();

        return Response.status(200).entity(output).build();
    }