当我尝试从xml
中的kony-fabric
响应生成XML树时,出现以下错误。
错误:无法生成XML
树。由于XML
无效,因此无法解析后端响应。第3行第139列的错误:属性构造错误
我的xml
回复来自konyfabric
:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/v1/xsl/xml_pretty_printer.xsl" type="text/xsl"?>
<categories currentPage="1" from="1" to="1" totalPages="1" total="1" queryTime="0.023" totalTime="0.028" canonicalUrl="/v1/categories(id="cat00000")?apiKey=lAqRUSojMrpkxyefjjfha" partial="false">
<category>
<id>cat00000</id>
<name>Best Buy</name>
<active>true</active>
<url>https://www.bestbuy.com/?cmp=RMX-cat</url>
<path>
<category>
<id>cat00000</id>
<name>Best Buy</name>
</category>
</path>
<subCategories>
<category>
<id>abcat0900000</id>
<name>Appliances</name>
</category>
<category>
<id>abcat0100000</id>
<name>TV & Home Theater</name>
</category>
<category>
<id>abcat0500000</id>
<name>Computers & Tablets</name>
</category>
<category>
<id>abcat0400000</id>
<name>Cameras & Camcorders</name>
</category>
<category>
<id>abcat0800000</id>
<name>Cell Phones</name>
</category>
<category>
<id>abcat0200000</id>
<name>Audio</name>
</category>
<category>
<id>abcat0700000</id>
<name>Video Games</name>
</category>
<category>
<id>abcat0600000</id>
<name>Movies & Music</name>
</category>
<category>
<id>abcat0300000</id>
<name>Car Electronics & GPS</name>
</category>
<category>
<id>pcmcat332000050000</id>
<name>Wearable Technology</name>
</category>
<category>
<id>pcmcat242800050021</id>
<name>Health, Fitness & Beauty</name>
</category>
<category>
<id>pcmcat312300050015</id>
<name>Home, Garage & Office</name>
</category>
<category>
<id>pcmcat254000050002</id>
<name>Smart Home</name>
</category>
<category>
<id>pcmcat252700050006</id>
<name>Drones, Toys & Collectibles</name>
</category>
<category>
<id>pcmcat142300050026</id>
<name>Best Buy Outlet</name>
</category>
<category>
<id>abcat0207000</id>
<name>Musical Instruments</name>
</category>
<category>
<id>cat09000</id>
<name>Gift Cards</name>
</category>
<category>
<id>abcat0010000</id>
<name>Gift Ideas</name>
</category>
<category>
<id>pcmcat128500050004</id>
<name>Name Brands</name>
</category>
<category>
<id>pcmcat1529524080138</id>
<name>Magnolia</name>
</category>
<category>
<id>pcmcat164600050001</id>
<name>Featured Offers</name>
</category>
<category>
<id>pcmcat1528819595254</id>
<name>Services</name>
</category>
<category>
<id>pcmcat230900050001</id>
<name>Best Buy Business</name>
</category>
<category>
<id>pcmcat356600050000</id>
<name>Best Buy Education</name>
</category>
<category>
<id>pcmcat144600050035</id>
<name>Electronics</name>
</category>
<category>
<id>pcmcat87800050001</id>
<name>Customer Service</name>
</category>
<category>
<id>pcmcat748302046864</id>
<name>Tech Help & Inspiration</name>
</category>
<category>
<id>sc_digital_platform</id>
<name>Digital Platform</name>
</category>
<category>
<id>pcmcat225600050002</id>
<name>Black Friday</name>
</category>
<category>
<id>pcmcat370900050002</id>
<name>Franchises</name>
</category>
<category>
<id>pcmcat140900050011</id>
<name>Top-Rated Products</name>
</category>
<category>
<id>pcmcat748302045953</id>
<name>AF TestingTemplates</name>
</category>
<category>
<id>pcmcat311300050017</id>
<name>Video Games, Movies & Music</name>
</category>
<category>
<id>pcmcat44800050004</id>
<name>Reward Zone</name>
</category>
<category>
<id>pcmcat140700050010</id>
<name>Special Sale</name>
</category>
<category>
<id>pcmcat128800050004</id>
<name>Reviews & Ratings</name>
</category>
<category>
<id>pcmcat149500050013</id>
<name>Best Buy Racing</name>
</category>
<category>
<id>pcmcat156400050050</id>
<name>Partsearch</name>
</category>
<category>
<id>pcmcat253600050018</id>
<name>e Gift Cards</name>
</category>
<category>
<id>pcmcat133200050003</id>
<name>Best Buy News</name>
</category>
</subCategories>
</category>
</categories>
当相同的api在 POSTMAN 客户端中给出有效的xml
响应时。
POSTMAN 客户端有效的xml
响应是:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/v1/xsl/xml_pretty_printer.xsl" type="text/xsl"?>
<categories currentPage="1" from="1" to="1" totalPages="1" total="1" queryTime="0.062" totalTime="0.068" canonicalUrl="/v1/categories(id="cat00000")?apiKey=lAqRUSojMrpkxyefjjfha" partial="false">
<category>
<id>cat00000</id>
<name>Best Buy</name>
<active>true</active>
<url>https://www.bestbuy.com/?cmp=RMX-cat</url>
<path>
<category>
<id>cat00000</id>
<name>Best Buy</name>
</category>
</path>
<subCategories>
<category>
<id>abcat0900000</id>
<name>Appliances</name>
</category>
<category>
<id>abcat0100000</id>
<name>TV & Home Theater</name>
</category>
<category>
<id>abcat0500000</id>
<name>Computers & Tablets</name>
</category>
<category>
<id>abcat0400000</id>
<name>Cameras & Camcorders</name>
</category>
<category>
<id>abcat0800000</id>
<name>Cell Phones</name>
</category>
<category>
<id>abcat0200000</id>
<name>Audio</name>
</category>
<category>
<id>abcat0700000</id>
<name>Video Games</name>
</category>
<category>
<id>abcat0600000</id>
<name>Movies & Music</name>
</category>
<category>
<id>abcat0300000</id>
<name>Car Electronics & GPS</name>
</category>
<category>
<id>pcmcat332000050000</id>
<name>Wearable Technology</name>
</category>
<category>
<id>pcmcat242800050021</id>
<name>Health, Fitness & Beauty</name>
</category>
<category>
<id>pcmcat312300050015</id>
<name>Home, Garage & Office</name>
</category>
<category>
<id>pcmcat254000050002</id>
<name>Smart Home</name>
</category>
<category>
<id>pcmcat252700050006</id>
<name>Drones, Toys & Collectibles</name>
</category>
<category>
<id>pcmcat142300050026</id>
<name>Best Buy Outlet</name>
</category>
<category>
<id>abcat0207000</id>
<name>Musical Instruments</name>
</category>
<category>
<id>cat09000</id>
<name>Gift Cards</name>
</category>
<category>
<id>abcat0010000</id>
<name>Gift Ideas</name>
</category>
<category>
<id>pcmcat128500050004</id>
<name>Name Brands</name>
</category>
<category>
<id>pcmcat1529524080138</id>
<name>Magnolia</name>
</category>
<category>
<id>pcmcat164600050001</id>
<name>Featured Offers</name>
</category>
<category>
<id>pcmcat1528819595254</id>
<name>Services</name>
</category>
<category>
<id>pcmcat230900050001</id>
<name>Best Buy Business</name>
</category>
<category>
<id>pcmcat356600050000</id>
<name>Best Buy Education</name>
</category>
<category>
<id>pcmcat144600050035</id>
<name>Electronics</name>
</category>
<category>
<id>pcmcat87800050001</id>
<name>Customer Service</name>
</category>
<category>
<id>pcmcat748302046864</id>
<name>Tech Help & Inspiration</name>
</category>
<category>
<id>sc_digital_platform</id>
<name>Digital Platform</name>
</category>
<category>
<id>pcmcat225600050002</id>
<name>Black Friday</name>
</category>
<category>
<id>pcmcat370900050002</id>
<name>Franchises</name>
</category>
<category>
<id>pcmcat140900050011</id>
<name>Top-Rated Products</name>
</category>
<category>
<id>pcmcat748302045953</id>
<name>AF TestingTemplates</name>
</category>
<category>
<id>pcmcat311300050017</id>
<name>Video Games, Movies & Music</name>
</category>
<category>
<id>pcmcat44800050004</id>
<name>Reward Zone</name>
</category>
<category>
<id>pcmcat140700050010</id>
<name>Special Sale</name>
</category>
<category>
<id>pcmcat128800050004</id>
<name>Reviews & Ratings</name>
</category>
<category>
<id>pcmcat149500050013</id>
<name>Best Buy Racing</name>
</category>
<category>
<id>pcmcat156400050050</id>
<name>Partsearch</name>
</category>
<category>
<id>pcmcat253600050018</id>
<name>e Gift Cards</name>
</category>
<category>
<id>pcmcat133200050003</id>
<name>Best Buy News</name>
</category>
</subCategories>
</category>
</categories>
答案 0 :(得分:1)
我只是通过两个不同的XML验证程序运行您的XML,但这不是有效的XML:
我得到:
XML文档中的错误: 3:139元素类型“类别”后面必须是属性说明“>”或“ />”。
所以这不是Kony Fabric的问题,而是后端的响应。
此错误是由canonicalUrl
元素中的categories
属性引起的。该属性的值包含双引号,即XML entity。您可以从下面屏幕快照的颜色变化中看到-cat00000
是黑色而不是绿色-它破坏了语法。
您必须使用单引号:
canonicalUrl="/v1/categories(id='cat00000')?apiKey=lAqRUSojMrpkxyefjjfha"
或使用XML实体名称对双引号进行转义:
canonicalUrl="/v1/categories(id="cat00000")?apiKey=lAqRUSojMrpkxyefjjfha"
然后此属性将有效。
但是,您将继续遇到TV & Home Theater
或Computers & Tablets
之类的值,因为与号&
也是XML实体。在所有这些情况下,您都必须将&
替换为"
。
我希望这会有所帮助。
答案 1 :(得分:1)
hi @Rishil我已经在在线xml
验证程序中检查了两个Response,并且您的第一个响应由Kony
生成,但有一个错误,由postman
生成的第二个响应是有效的。因此,Kony fabric
中可能存在问题。
我同意@ Mig82的声明“使用XML实体名称转义双引号:”
canonicalUrl="/v1/categories(id="cat00000")?apiKey=lAqRUSojMrpkxyefjjfha"
由postman
管理得很好。
我希望这对您有帮助。