Issue as The element 'ImageParameters' cannot contain child element 'ImageParameter'

一世执手 提交于 2019-12-14 03:45:47

问题


I am trying to generating the usps label with 4x6 but I am facing this issue. Can any one help me out for generating 4x6Label.

Also I tried changing the version from DeliveryConfirmationV3 to DeliveryConfirmationV4 but still it is not generating 4x6Label.

My xml request is passing as

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>

but I am receiving error as

<?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/>

Initially it was working perfectly but after passing

<ImageParameter>4X6LABEL</ImageParameter>

this issue arises

Currently my code is as

   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;
}   

I had updated the above code but I m getting issue as

Console


回答1:


Regarding the original problem:

The 4X6LABEL is not available for the DeliveryConfirmationV3 API. To use this option, chose an API that supports it. (you have to decide between PriorityMailIntl and eVS among others, depending on your need)

Your updated code:

You specifiy <ImageType>TIF</ImageType> for whatever reason, but it seems like you try to use the returned data as PDF. Try to save and open them as TIF to test your current results and try to change the requested ImageType to PDF in order to get your probably desired result.



来源:https://stackoverflow.com/questions/45803982/issue-as-the-element-imageparameters-cannot-contain-child-element-imageparame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!