使用xml2js无效字符解析XML Soap请求

时间:2018-10-31 20:51:01

标签: meteor soap iron-router xml2js

我正在尝试使用API​​端点设置我的Meteor应用程序,以在列出的商品发生更改或交易时接收Ebay卖家通知。

我遵循了{@ {3}}的流星厨师的指南。

尝试使用流星API时遇到的第一个问题是,请求中的body出现在空对象上,我已经读到流星1.12以来的所有XML POST请求。

遵循writing an api之后,我能够将所需的XML放入rawBody中并从context.request.rawBody访问它。

我现在遇到的问题是尝试解析SOAP XML。这是我收到的错误:

[ 
  Error: Invalid character in entity name
  Line: 38
  Column: 82
  Char: =
]

我尝试了ignoreAttrs,mergeAttrs以及几个xml2js解析器选项的几种组合,以尝试克服这一点。

我正在使用Postman进行测试,这是我正在用于测试的原始text / xml输入:

(来自eBay API文档的示例ItemListed通知)

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://
        www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Header>
    <ebl:RequesterCredentials soapenv:mustUnderstand="0" xmlns:ns="urn:ebay:apis:eBLBaseComponents"
        xmlns:ebl="urn:ebay:apis:eBLBaseComponents">
      <ebl:NotificationSignature xmlns:ebl="urn:ebay:apis:eBLBaseComponents">DYrq65GiZvg4cLFfW8J/Mg==</ebl:NotificationSignature>
    </ebl:RequesterCredentials>
  </soapenv:Header>
  <soapenv:Body>
    <GetItemResponse xmlns="urn:ebay:apis:eBLBaseComponents">
      <Timestamp>2011-01-06T08:08:13.025Z</Timestamp>
      <Ack>Success</Ack>
      <CorrelationID>476457080</CorrelationID>
      <Version>699</Version>
      <Build>E699_CORE_BUNDLED_12457306_R1</Build>
      <NotificationEventName>ItemListed</NotificationEventName>
      <RecipientUserID>testuser_magicalbookseller</RecipientUserID>
      <EIASToken>nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wFk4CpDZSLpwqdj6x9nY+seQ**</EIASToken>
      <Item>
        <AutoPay>false</AutoPay>
        <BuyerProtection>ItemIneligible</BuyerProtection>
        <BuyItNowPrice currencyID="USD">0.0</BuyItNowPrice>
        <Country>US</Country>
        <Currency>USD</Currency>
        <GiftIcon>0</GiftIcon>
        <HitCounter>NoHitCounter</HitCounter>
        <ItemID>110066229557</ItemID>
        <ListingDetails>
          <Adult>false</Adult>
          <BindingAuction>false</BindingAuction>
          <CheckoutEnabled>true</CheckoutEnabled>
          <ConvertedBuyItNowPrice currencyID="USD">0.0</ConvertedBuyItNowPrice>
          <ConvertedStartPrice currencyID="USD">1.0</ConvertedStartPrice>
          <ConvertedReservePrice currencyID="USD">0.0</ConvertedReservePrice>
          <HasReservePrice>false</HasReservePrice>
          <StartTime>2011-01-06T08:07:54.000Z</StartTime>
          <EndTime>2011-01-13T08:07:54.000Z</EndTime>
          <ViewItemURL>http://cgi.sandbox.ebay.com/ws/eBayISAPI.dll?ViewItem&item=110066229557&category=377</ViewItemURL>
          <HasUnansweredQuestions>false</HasUnansweredQuestions>
          <HasPublicMessages>false</HasPublicMessages>
          <ExpressListing>false</ExpressListing>
        </ListingDetails>
        <ListingDuration>Days_7</ListingDuration>
        <ListingType>Chinese</ListingType>
        <Location>San Jose, California</Location>
        <PaymentMethods>PayPal</PaymentMethods>
        <PayPalEmailAddress>magicalbookseller@yahoo.com</PayPalEmailAddress>
        <PrimaryCategory>
          <CategoryID>377</CategoryID>
          <CategoryName>Books:Fiction &amp; Literature</CategoryName>
        </PrimaryCategory>
        <PrivateListing>false</PrivateListing>
        <Quantity>1</Quantity>
        <ReservePrice currencyID="USD">0.0</ReservePrice>
        <ReviseStatus>
          <ItemRevised>false</ItemRevised>
        </ReviseStatus>
        <Seller>
          <AboutMePage>false</AboutMePage>
          <Email>testuser_magicalbookseller@yahoo.com</Email>
          <FeedbackScore>31</FeedbackScore>
          <PositiveFeedbackPercent>100.0</PositiveFeedbackPercent>
          <FeedbackPrivate>false</FeedbackPrivate>
          <FeedbackRatingStar>Yellow</FeedbackRatingStar>
          <IDVerified>true</IDVerified>
          <eBayGoodStanding>true</eBayGoodStanding>
          <NewUser>false</NewUser>
          <RegistrationDate>2010-01-01T00:00:00.000Z</RegistrationDate>
          <Site>US</Site>
          <Status>Confirmed</Status>
          <UserID>testuser_magicalbookseller</UserID>
          <UserIDChanged>false</UserIDChanged>
          <UserIDLastChanged>2007-11-29T18:43:54.000Z</UserIDLastChanged>
          <VATStatus>NoVATTax</VATStatus>
          <SellerInfo>
            <AllowPaymentEdit>true</AllowPaymentEdit>
            <CheckoutEnabled>true</CheckoutEnabled>
            <CIPBankAccountStored>false</CIPBankAccountStored>
            <GoodStanding>true</GoodStanding>
            <LiveAuctionAuthorized>false</LiveAuctionAuthorized>
            <MerchandizingPref>OptIn</MerchandizingPref>
            <QualifiesForB2BVAT>false</QualifiesForB2BVAT>
            <StoreOwner>true</StoreOwner>
            <StoreURL>http://www.stores.sandbox.ebay.com/id=132854966</StoreURL>
            <ExpressEligible>false</ExpressEligible>
            <ExpressWallet>false</ExpressWallet>
            <SafePaymentExempt>false</SafePaymentExempt>
          </SellerInfo>
          <MotorsDealer>false</MotorsDealer>
        </Seller>
        <SellingStatus>
          <BidCount>0</BidCount>
          <BidIncrement currencyID="USD">0.25</BidIncrement>
          <ConvertedCurrentPrice currencyID="USD">1.0</ConvertedCurrentPrice>
          <CurrentPrice currencyID="USD">1.0</CurrentPrice>
          <LeadCount>0</LeadCount>
          <MinimumToBid currencyID="USD">1.0</MinimumToBid>
          <QuantitySold>0</QuantitySold>
          <ReserveMet>true</ReserveMet>
          <SecondChanceEligible>false</SecondChanceEligible>
          <ListingStatus>Active</ListingStatus>
        </SellingStatus>
        <ShippingDetails>
          <ApplyShippingDiscount>false</ApplyShippingDiscount>
          <CalculatedShippingRate>
            <OriginatingPostalCode>95125</OriginatingPostalCode>
            <PackageDepth measurementSystem="English" unit="inches">2</PackageDepth>
            <PackageLength measurementSystem="English" unit="inches">10</PackageLength>
            <PackageWidth measurementSystem="English" unit="inches">7</PackageWidth>
            <PackagingHandlingCosts currencyID="USD">0.0</PackagingHandlingCosts>
            <ShippingIrregular>false</ShippingIrregular>
            <ShippingPackage>PackageThickEnvelope</ShippingPackage>
            <WeightMajor measurementSystem="English" unit="lbs">2</WeightMajor>
            <WeightMinor measurementSystem="English" unit="oz">0</WeightMinor>
          </CalculatedShippingRate>
          <SalesTax>
            <SalesTaxPercent>0.0</SalesTaxPercent>
            <ShippingIncludedInTax>false</ShippingIncludedInTax>
          </SalesTax>
          <ShippingServiceOptions>
            <ShippingService>USPSMedia</ShippingService>
            <ShippingServicePriority>1</ShippingServicePriority>
            <ExpeditedService>false</ExpeditedService>
            <ShippingTimeMin>2</ShippingTimeMin>
            <ShippingTimeMax>9</ShippingTimeMax>
          </ShippingServiceOptions>
          <ShippingType>Calculated</ShippingType>
          <ThirdPartyCheckout>false</ThirdPartyCheckout>
          <ExcludeShipToLocation>Asia</ExcludeShipToLocation>
          <ExcludeShipToLocation>Middle East</ExcludeShipToLocation>
          <ExcludeShipToLocation>Southeast Asia</ExcludeShipToLocation>
          <SellerExcludeShipToLocationsPreference>true</SellerExcludeShipToLocationsPreference>
        </ShippingDetails>
        <ShipToLocations>US</ShipToLocations>
        <Site>US</Site>
        <StartPrice currencyID="USD">1.0</StartPrice>
        <Storefront>
          <StoreCategoryID>1</StoreCategoryID>
          <StoreCategory2ID>0</StoreCategory2ID>
          <StoreURL>http://www.stores.sandbox.ebay.com/id=132854966</StoreURL>
        </Storefront>
        <TimeLeft>P6DT23H59M42S</TimeLeft>
        <Title>Harry Potter and the Philosopher&apos;s Stone</Title>
        <UUID>CD751A9973E249ABB880E1B2DF65B50B</UUID>
        <HitCount>0</HitCount>
        <LocationDefaulted>true</LocationDefaulted>
        <GetItFast>false</GetItFast>
        <PostalCode>95125</PostalCode>
        <PictureDetails>
          <GalleryType>Gallery</GalleryType>
          <GalleryURL>http://i1.sandbox.ebayimg.com/03/i/00/3e/60/d7_1.JPG?set_id=8800005007</GalleryURL>
          <PhotoDisplay>PicturePack</PhotoDisplay>
          <PictureURL>http://i1.sandbox.ebayimg.com/03/i/00/3e/60/d7_1.JPG?set_id=8800005007</PictureURL>
        </PictureDetails>
        <DispatchTimeMax>3</DispatchTimeMax>
        <ProxyItem>false</ProxyItem>
        <BuyerGuaranteePrice currencyID="USD">20000.0</BuyerGuaranteePrice>
        <IntangibleItem>false</IntangibleItem>
        <ReturnPolicy>
          <RefundOption>MoneyBack</RefundOption>
          <Refund>Money Back</Refund>
          <ReturnsWithinOption>Days_30</ReturnsWithinOption>
          <ReturnsWithin>30 Days</ReturnsWithin>
          <ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
          <ReturnsAccepted>Returns Accepted</ReturnsAccepted>
          <Description>This is the first book in the Harry Potter series. In excellent condition!</Description>
          <ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
          <ShippingCostPaidBy>Buyer</ShippingCostPaidBy>
        </ReturnPolicy>
        <PaymentAllowedSite>eBayMotors</PaymentAllowedSite>
        <PaymentAllowedSite>CanadaFrench</PaymentAllowedSite>
        <PaymentAllowedSite>Canada</PaymentAllowedSite>
        <PaymentAllowedSite>US</PaymentAllowedSite>
        <ConditionID>1000</ConditionID>
        <ConditionDisplayName>Brand New</ConditionDisplayName>
      </Item>
    </GetItemResponse>
  </soapenv:Body>
</soapenv:Envelope>

此外,在类似于生产环境的设置中进行测试时,我收到有关request entity too large的服务器错误。我现在不知道该怎么办。

任何帮助将不胜感激。

提前感谢您的时间。

1 个答案:

答案 0 :(得分:0)

问题是<ViewItemURL>中的URL中有一个&符,这是XML中的无效字符,&必须为&amp;

幸运的是,这是eBay文档中一个不好的例子。此错误不是实时发生的,因为ViewItemURL在实际的eBay通知中已正确转义。

当我自己在eBay示例中摆脱了&符时,它就很好了。