【问题标题】:Issue as The element 'ImageParameters' cannot contain child element 'ImageParameter'问题为元素“ImageParameters”不能包含子元素“ImageParameter”
【发布时间】:2017-08-31 21:31:36
【问题描述】:

我正在尝试使用 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;
}   

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

控制台

【问题讨论】:

  • 错误消息包含提示“内容模型仅是文本”,这意味着图像参数必须作为属性或作为 标记的内容包含,例如 &lt;imageparameters attributex="4X6LABEL"&gt;&lt;/imageparameters&gt;或喜欢&lt;imageparameters&gt;4X6LABEL&lt;/imageparameters&gt;。你有那个 Api 的 xsd 或文档,应该在哪里解释?
  • @dlatikay 我已经查看了usps.com/business/web-tools-apis/… 并添加了图像参数
  • 现在我也看到了,你是对的,它在他们的样本中和你拥有的完全一样。看起来有些 API 版本冲突。
  • 你为什么有API=DeliveryConfirmationV3?我对这个话题一点都不熟悉,但是当我搜索这个话题时,我发现了以下内容:usps.com/business/web-tools-apis/…,它只提到了API=eVSAPI=eVSCertify。你能添加一个提到API=DeliveryConfirmationV3 的文档链接吗?
  • 刚刚查看了您 8 月 21 日的评论。您可以参考API=PriorityMailIntl 的文档 - 所以不要指望它在不使用此 API 的情况下工作;)

标签: c# .net xml usps


【解决方案1】:

关于原问题:

4X6LABEL 不适用于 DeliveryConfirmationV3 API。要使用此选项,请选择支持它的 API。 (你必须在PriorityMailIntleVS 之间做出选择,这取决于你的需要)

您更新的代码:

无论出于何种原因,您都指定了&lt;ImageType&gt;TIF&lt;/ImageType&gt;,但您似乎尝试将返回的数据用作PDF。尝试将它们保存并打开为 TIF 以测试您当前的结果,并尝试将请求的 ImageType 更改为 PDF 以获得您可能想要的结果。

【讨论】:

    猜你喜欢
    • 2010-12-17
    • 1970-01-01
    • 1970-01-01
    • 2017-03-28
    • 2017-05-25
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    相关资源
    最近更新 更多