Search code examples
xmlupswell-formed

Can anyone please tell me how this is not well formed XML?


Context: I am trying to send a test request to ShipAccept api for UPS. I am receiving an error telling me the xml doc is not well formed. The actual request I am sending has all of the required information, this is simply the same formatting.

<AccessRequest xml:lang="en-US">
  <AccessLicenseNumber>Your_License</AccessLicenseNumber>
  <UserId>Your_ID</UserId>
  <Password>Your_Password</Password>
</AccessRequest> 
</?xml version="1.0"?>
<ShipmentConfirmRequest xml:lang="en-US">
  <Request>
    <TransactionReference>
      <CustomerContext>Customer Comment</CustomerContext>
    </TransactionReference>
    <RequestAction>ShipConfirm</RequestAction>
    <RequestOption>validate</RequestOption>
  </Request>
  <LabelSpecification>
    <LabelPrintMethod>
      <Code>GIF</Code>
      <Description>gif file</Description>
    </LabelPrintMethod>
    <HTTPUserAgent>Mozilla/4.5</HTTPUserAgent>
    <LabelImageFormat>
      <Code>GIF</Code>
      <Description>gif</Description>
    </LabelImageFormat>
  </LabelSpecification>
  <Shipment>
   <RateInformation>
      <NegotiatedRatesIndicator/> 
    </RateInformation> 
    <Description/>
    <Shipper>
      <Name>Shipper Name</Name>
      <PhoneNumber>1234567890</PhoneNumber>
      <ShipperNumber>Ship Number</ShipperNumber>
      <TaxIdentificationNumber>1234567877</TaxIdentificationNumber>
      <Address>
        <AddressLine1>Address Line</AddressLine1>
        <City>City</City>
        <StateProvinceCode>MD</StateProvinceCode>
        <PostalCode>21093</PostalCode>
        <PostcodeExtendedLow></PostcodeExtendedLow>
        <CountryCode>US</CountryCode>
     </Address>
    </Shipper>
    <ShipTo>
     <CompanyName>Ship To Company Name</CompanyName>
      <AttentionName>Ship To Attn Name</AttentionName>
      <PhoneNumber>97225377171</PhoneNumber>
      <Address>
        <AddressLine1>Address Line</AddressLine1>
        <City>City</City>
        <StateProvinceCode>FL</StateProvinceCode>
        <PostalCode>32960</PostalCode>
        <CountryCode>US</CountryCode>
      </Address>
    </ShipTo>
    <ShipFrom>
      <CompanyName>Ship From Company Name</CompanyName>
      <AttentionName>Ship From Attn Name</AttentionName>
      <PhoneNumber>1234567890</PhoneNumber>
      <TaxIdentificationNumber>1234567877</TaxIdentificationNumber>
      <Address>
        <AddressLine1>Address Line</AddressLine1>
        <City>City</City>
        <StateProvinceCode>MD</StateProvinceCode>
        <PostalCode>21093</PostalCode>
        <CountryCode>US</CountryCode>
      </Address>
    </ShipFrom>
     <PaymentInformation>
      <Prepaid>
        <BillShipper>
          <AccountNumber>Ship Number</AccountNumber>
        </BillShipper>
      </Prepaid>
    </PaymentInformation>
    <Service>
      <Code>02</Code>
      <Description>2nd Day Air</Description>
    </Service>
    <Package>
      <PackagingType>
        <Code>02</Code>
        <Description>Customer Supplied</Description>
      </PackagingType>
      <Description>Package Description</Description>
      <ReferenceNumber>
        <Code>00</Code>
        <Value>Package</Value>
      </ReferenceNumber>
      <PackageWeight>
        <UnitOfMeasurement/>
        <Weight>60.0</Weight>
      </PackageWeight>
      <LargePackageIndicator/>
      <AdditionalHandling>0</AdditionalHandling>
    </Package>
  </Shipment>
</ShipmentConfirmRequest>

Also, does the indenting matter for xml? Could the fact that my indenting is wrong be why the document is not well-formed? I am not experienced with xml what-so-ever, but unfortunately the UPS api accepts most things as json EXCEPT for the shipping parts. Thank you so much for any help you could offer me ahead of time!

EDIT: The provided code is their own example of a proper request, so I am beyond baffled.


Solution

  • An XML document can only have one root. What you have here is two XML documents concatenated with a typo in the declaration of the second one.

    </AccessRequest>          <-- end of the root element of the 1st doc
    
    
    </?xml version="1.0"?>   <-- Probably an XML declaration of the 2nd doc.
                                 Shouldn't have the slash.
    <ShipmentConfirmRequest xml:lang="en-US">