2

I get below error when I tried to generate XML tree from xml response in kony-fabric.

error : Cannot generate XML tree. Failed to parse Backend Response as XML is invalid. error on line 3 at column 139: attributes construct error

enter image description here

my xml response is from 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>

When same api give valid xml response in POSTMAN client.

POSTMAN client valid xml response is:

<?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=&quot;cat00000&quot;)?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 &amp; Home Theater</name>
            </category>
            <category>
                <id>abcat0500000</id>
                <name>Computers &amp; Tablets</name>
            </category>
            <category>
                <id>abcat0400000</id>
                <name>Cameras &amp; 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 &amp; Music</name>
            </category>
            <category>
                <id>abcat0300000</id>
                <name>Car Electronics &amp; GPS</name>
            </category>
            <category>
                <id>pcmcat332000050000</id>
                <name>Wearable Technology</name>
            </category>
            <category>
                <id>pcmcat242800050021</id>
                <name>Health, Fitness &amp; Beauty</name>
            </category>
            <category>
                <id>pcmcat312300050015</id>
                <name>Home, Garage &amp; Office</name>
            </category>
            <category>
                <id>pcmcat254000050002</id>
                <name>Smart Home</name>
            </category>
            <category>
                <id>pcmcat252700050006</id>
                <name>Drones, Toys &amp; 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 &amp; 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 &amp; 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 &amp; 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>
Rishil Patel
  • 1,977
  • 3
  • 14
  • 30

2 Answers2

1

I just ran your XML through two different XML validators and it's not valid XML:

I get:

Errors in the XML document: 3: 139 Element type "categories" must be followed by either attribute specifications, ">" or "/>".

So this is not an issue with Kony Fabric, but rather with the response from your backend.

This error is caused by the canonicalUrl attribute in the categories element. The value for this attribute contains a double quote, which is an XML entity. You can see from the color change in screenshot below -where cat00000 is black instead of green- that it breaks the syntax.

enter image description here

You have to either use single quotes:

canonicalUrl="/v1/categories(id='cat00000')?apiKey=lAqRUSojMrpkxyefjjfha"

Or escape the double quotes using the XML entity name:

canonicalUrl="/v1/categories(id=&quot;cat00000&quot;)?apiKey=lAqRUSojMrpkxyefjjfha"

Then this attribute will be valid.

However, you will continue to have issues with values such as TV & Home Theater or Computers & Tablets because the ampersand & character is also an XML entity. In all of these cases you will have to replace & with &quot;.

I hope this helps.

Mig82
  • 4,856
  • 4
  • 40
  • 63
  • I have checked and confirmed that first xml which generated by kony throw an error but second response generated by postman and it doesn't throw any error on same url. Have you checked that url in postman with using your apikey? – Rishil Patel Mar 27 '19 at 12:16
  • @RishilP. you assume I have an API key for whatever service you are invoking, which is not the case. Also, I'm not sure what you mean by *"xml which generated by kony throw an error but second response generated by postman"*. Please amend the question to better explain where you're getting the first XML and where you're getting the second one. Add screenshots for clarity. – Mig82 Mar 27 '19 at 14:25
  • 1
    First response I get in kony fabric but when try to check that response in xpath mode that time fabric give me an error invalid xml and that happened only in category list api. And the same response which I got in kony fabric, I had tried to check online validator it also gave me an error what you mention for "line 3 cannonical url". - my point is why I got invalid response in kony fabric but same url gave me valid xml in postman client. Hope you are understand my what my point is. – Rishil Patel Mar 27 '19 at 14:33
  • Wait, is your backend producing bad XML -with `"` and `&`- or is it producing valid XML -with `"` and `&`? – Mig82 Mar 29 '19 at 12:05
  • 1
    Just in case the backend is producing bad XML and Postman is somehow smart enough to fix it, try calling the same backend using cURL. Postman has an option to copy the equivalent cURL invocation. If the XML from the backend is valid -with `"` and `&`- then this could in fact be a problem in Fabric. – Mig82 Mar 29 '19 at 12:07
  • 1
    Yes, my main question is that api response produce valid xml in postman but not in kony fabric. So please check your answer you have wrote this is not an issue with kony fabric! So do you think this is valid answer? – Rishil Patel Mar 29 '19 at 14:01
  • The Fabric Console and the Fabric runtime are different components. If your backend is responding valid XML with `"` and `&` then it's possible that Fabric runtime is decoding that into `"` and `&`, thus creating a problem for the Console to parse it and create the visualisation tree. I've tagged the Product Team [on your question in Basecamp](https://basecamp.kony.com/s/question/0D56A00001JMAMtSAP/problem-in-xml-response). Again, did you try the same endpoint from cURL to validate that the backend's response uses `"` and `&`? – Mig82 Mar 30 '19 at 13:42
1

hi @Rishil I have checked both Response in online xml validator and there is an error with your first response which generated by Kony but the second response by postman is valid. So there may be an issue in Kony fabric.

I am agree with @Mig82's statements "escape the double quotes using the XML entity name:"

canonicalUrl="/v1/categories(id=&quot;cat00000&quot;)?apiKey=lAqRUSojMrpkxyefjjfha"

which is well managed by postman.

I hope this will helpful to you.

john Smith
  • 56
  • 3
  • I am agree with your and @Mig82's answer. That may be issue with "kony fabric". By the way thanks for your time. :) – Rishil Patel Mar 29 '19 at 16:02
  • @RishilP. I know you had flagged mine as the correct answer. Is there any reason you changed your mind again? – Mig82 Apr 17 '19 at 13:43
  • Yes, your answer say there is issue with my backend not with kony fabric. And I am using very accurate API. So I am not agree with that. – Rishil Patel Apr 17 '19 at 14:00