问题元素'ImageParameters'不能包含子元素'ImageParameter'

时间:2017-08-21 19:02:07

标签: c# .net xml usps

我正在尝试使用4x6生成usps标签,但我正面临这个问题。任何人都可以帮助我生成4x6Label。

此外,我尝试将版本从DeliveryConfirmationV3更改为DeliveryConfirmationV4,但仍然没有生成4x6Label。

我的xml请求正在传递

https://secure.shippingapis.com/ShippingAPI.dll?API=DeliveryConfirmationV3&XML=<DeliveryConfirmationV3.0Request USERID="xxxxx" PASSWORD="xxxxxx">
<Option>1</Option>
<ImageParameters>
    <ImageParameter>4X6LABEL</ImageParameter>
</ImageParameters>
<FromName>Mitesh1 Jain1</FromName>
<FromFirm></FromFirm>
<FromAddress1>52 NORMANDY RD</FromAddress1>
<FromAddress2>QWE</FromAddress2>
<FromCity>MARLTON</FromCity>
<FromState>NJ</FromState>
<FromZip5>08053</FromZip5>
<FromZip4></FromZip4>
<ToName>DISCRETE JRC,LLC</ToName>
<ToFirm></ToFirm>
<ToAddress1>110 South 8th Street</ToAddress1>
<ToAddress2>Suite 104</ToAddress2>
<ToCity>Philadelphia</ToCity>
<ToState>PA</ToState>
<ToZip5>15001</ToZip5>
<ToZip4></ToZip4>
<WeightInOunces>1</WeightInOunces>
<ServiceType>Priority</ServiceType>
<POZipCode></POZipCode>
<ImageType>PDF</ImageType>
<LabelDate></LabelDate>
<CustomerRefNo></CustomerRefNo>
<AddressServiceRequested>False</AddressServiceRequested>
<SenderName></SenderName>
<SenderEMail></SenderEMail>
<RecipientName></RecipientName>
<RecipientEMail></RecipientEMail>
</DeliveryConfirmationV3.0Request>

但我收到错误

<?xml version="1.0" encoding="utf-8"?>
<Error>
<Number>-2147221202</Number>
<Source>Common:XmlParse</Source>
<Description>The element 'ImageParameters' cannot contain child element 'ImageParameter' because the parent element's content model is text only.</Description>
 <HelpFile/>
 <HelpContext/>

最初它完美地工作但是在传递之后

<ImageParameter>4X6LABEL</ImageParameter>

出现了这个问题

目前我的代码是

   public Package GetDeliveryConfirmationLabel(Package package)
{
    string labeldate = package.ShipDate.ToShortDateString();
    if (package.ShipDate.ToShortDateString() == DateTime.Now.ToShortDateString()) 
        labeldate = "";
       string url= "https://secure.shippingapis.com/ShippingAPI.dll?API=PriorityMailIntlCertify&XML= <PriorityMailIntlCertifyRequest USERID=\"XXXXX\"> <Option></Option> <Revision>2</Revision> <ImageParameters> <ImageParameter>4X6LABEL</ImageParameter> </ImageParameters> <FromFirstName>Garth</FromFirstName> <FromMiddleInitial>A</FromMiddleInitial> <FromLastName>Brooks</FromLastName> <FromFirm>Garths Firm</FromFirm> <FromAddress1>radlab</FromAddress1> <FromAddress2>6406 Ivy Lane</FromAddress2> <FromUrbanization>Garys Urbanization</FromUrbanization> <FromCity>Greenbelt</FromCity> <FromState>MD</FromState> <FromZip5>20770</FromZip5> <FromZip4>1234</FromZip4> <FromPhone>3019187658</FromPhone> <FromCustomsReference> From Customs Ref.</FromCustomsReference> <ToName></ToName> <ToFirstName>Reza</ToFirstName> <ToLastName>Dianat</ToLastName> <ToFirm>HP</ToFirm> <ToAddress1>HP</ToAddress1> <ToAddress2>5th floor</ToAddress2> <ToAddress3>6406 Flower Lane</ToAddress3> <ToCity>Greenbelt</ToCity> <ToProvince>Md</ToProvince> <ToCountry>Canada</ToCountry> <ToPostalCode>20770</ToPostalCode> <ToPOBoxFlag>N</ToPOBoxFlag> <ToPhone>5555555555</ToPhone> <ToFax>3012929999</ToFax> <ToEmail>b@aol.com</ToEmail> <ToCustomsReference>Import Reference</ToCustomsReference> <NonDeliveryOption>Return</NonDeliveryOption> <Container>MDFLATRATEBOX</Container> <ShippingContents> <ItemDetail> <Description>Description 1</Description> <Quantity>1</Quantity> <Value>1.11</Value> <NetPounds>1</NetPounds> <NetOunces>1</NetOunces> <HSTariffNumber>123456789123</HSTariffNumber> <CountryOfOrigin>Brazil</CountryOfOrigin> </ItemDetail> <ItemDetail> <Description>Description 2</Description> <Quantity>2</Quantity> <Value>2.22</Value> <NetPounds></NetPounds> <NetOunces>2</NetOunces> <HSTariffNumber>234567</HSTariffNumber> <CountryOfOrigin>Switzerland</CountryOfOrigin> </ItemDetail> <ItemDetail> <Description>Description 3</Description> <Quantity>3</Quantity> <Value>3.33</Value> <NetPounds></NetPounds> <NetOunces>3</NetOunces> <HSTariffNumber>123456789123</HSTariffNumber> <CountryOfOrigin>Brazil</CountryOfOrigin> </ItemDetail> <ItemDetail> <Description>Description 4</Description> <Quantity>4</Quantity> <Value>4.44</Value> <NetPounds></NetPounds> <NetOunces>4</NetOunces> <HSTariffNumber>234567234567</HSTariffNumber> <CountryOfOrigin>Switzerland</CountryOfOrigin> </ItemDetail> </ShippingContents> <Insured>N</Insured> <InsuredNumber>90123</InsuredNumber> <InsuredAmount>99.90</InsuredAmount> <GrossPounds>3</GrossPounds> <GrossOunces>8</GrossOunces> <ContentType>Documents</ContentType> <ContentTypeOther>and Other</ContentTypeOther> <Agreement>Y</Agreement> <Comments>PriorityMailIntl Comments</Comments> <LicenseNumber>Lic 123</LicenseNumber> <CertificateNumber>Cert456</CertificateNumber> <InvoiceNumber>Inv890</InvoiceNumber> <ImageType>TIF</ImageType> <ImageLayout>TRIMONEPERFILE</ImageLayout> <CustomerRefNo>Cust Ref123</CustomerRefNo> <POZipCode>20770</POZipCode> <LabelDate></LabelDate> <HoldForManifest>N</HoldForManifest> <EELPFC>802.11B</EELPFC> <CommercialPrice></CommercialPrice> <Size></Size> <Length></Length> <Width></Width> <Height></Height> <Girth></Girth> <ExtraServices> <ExtraService></ExtraService> </ExtraServices> </PriorityMailIntlCertifyRequest>"; 

     string xml = web.DownloadString(url);
    if (xml.Contains("<Error>"))
    {
        int idx1 = xml.IndexOf("<Description>") + 13;
        int idx2 = xml.IndexOf("</Description>");
        int l = xml.Length;
        string errDesc = xml.Substring(idx1, idx2 - idx1);
        package.Error = errDesc;
        //throw new USPSManagerException(errDesc);
    }
    else
    {
         int i1 = xml.IndexOf("<LabelImage>") + "<LabelImage>".Length;
         int i2 = xml.IndexOf("</LabelImage>");
         package.ShippingLabel = Convert.FromBase64String(xml.Substring(i1, i2 - i1));

         XmlDocument xmldoc = new XmlDocument();
         xmldoc.LoadXml(xml);
         XmlNodeList nodeList = xmldoc.GetElementsByTagName("LabelImage");
        string _DeliveryConfirmationNumber = string.Empty;
        foreach (XmlNode node in nodeList)
        {
            _DeliveryConfirmationNumber = node.InnerText;
        }
        package.ReferenceNumber = _DeliveryConfirmationNumber;
    }
    return package;
}   

我已经更新了上面的代码,但我的问题是

enter image description here

控制台

enter image description here

1 个答案:

答案 0 :(得分:0)

关于原始问题:

4X6LABEL API无法使用DeliveryConfirmationV3。要使用此选项,请选择支持它的API。 (根据您的需要,您必须在PriorityMailIntleVS之间做出决定)

您的更新代码:

您出于某种原因指定<ImageType>TIF</ImageType>,但似乎您尝试将返回的数据用作PDF。尝试保存并打开它们作为TIF来测试您当前的结果,并尝试将请求的ImageType更改为PDF,以获得您可能想要的结果。