Jeff Hannes Posted January 25, 2007 Posted January 25, 2007 I am attempting to write code to import information from Amazon via XML...I have some experience writing XSL code for FileMaker import (was able to do it with Yahoo Merchant Solutions), but I have hit a snag with Amazon I haven't been able to overcome. Here's what I've got...First, a sample of the XML code returned by Amazon: <?xml version="1.0" encoding="UTF-8"?> True B000KL8SZ8 B000KL8SZ8 Jakks Toy BIG SHOW DELUXE AGGRESSION 5 WWE JAKKS FIGURE And here is the XSLT stylesheet I wrote to parse the information: <?xml version="1.0" encoding="UTF-8"?> 0 YES 1 ASIN TEXT 0 0 As that code stands right now, I can't get it to work. However, if I remove a line of code from the XML, it works fine. Specifically, if I change to it works just fine. But if I leave the code as is, then it imports 0 records and is unable to parse the XML. In the final solution I cannot make modifications to Amazon's XML output (ultimately the goal is to pull directly from Amazon without the in-between of working with a local file) so any changs I make MUST be to the stylesheet and not to the XML file. Any clues as to what my problem is and how I can fix it?
Fenton Posted January 25, 2007 Posted January 25, 2007 The problem is that Amazon decided at some point to add its own namespace to the data returned. Originally they didn't, so it's thrown many for a loop. Amazon adds theirs here: FileMaker does this with their data also; here: A namespace attached to the root element automatically extends to all elements below, unless they are specifically assigned to another namespace themselves. In order to parse FileMaker data for other apps, you often have to add its namespace, to the tag, define a prefix for it, usually "fm" or "fmp", then exclude it (like you tried to do with "xml"). So, going in the other direction, bringing Amazon data directly into FileMaker, you have do that same thing with the Amazon namespace; define it, give it a prefix (I'm using "aws"), then exclude from the result: <?xml version="1.0" encoding="UTF-8"?> xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2005-10-05" exclude-result-prefixes="aws"> 0 YES 1 ASIN TEXT 0 0
Jeff Hannes Posted January 25, 2007 Author Posted January 25, 2007 Perfect. Thanks so much! Now I need to actually learn a little bit about namespaces so I fully understand what you did here. But in the meantime I can at least start gathering data on a larger scale. I greatly appreciate the quick and thorough response. - Jeff
Fenton Posted January 26, 2007 Posted January 26, 2007 Well, they confuse me a bit also; but I usually manage to figure out how to get what I want. The reasoning behind namespaces is simple. It lets each application (in the broad sense of the term) explicitly own all its elements, so they cannot be confused with same-named elements of another application. It doesn't matter much to us lightweights. But I imagine it might if you were gathering data from two different xml sources into one document, and they both used the same name for an element, but meant different things. Yeah, kind of far-fetched, but they were designing for the future; which is generally a good idea because it tends to arrive someday.
Roy Osborn Posted February 12, 2007 Posted February 12, 2007 That makes perfect sense. I'm having similar troubles with Yahoo XML results. any ideas on how to transform this to simply ""? Of course, I manually remove it, and still have other issues further down the tree, but I can't seem to cross the first bridge!
kfutter Posted January 26, 2009 Posted January 26, 2009 (edited) Apologies for digging up an old thread, but I'm having a similar problem to Jeff. I've used Fenton's amended XSLT example, and FM seems to process it without error, but nothing is imported. Have things changed since this thread came into being? EDIT I got it working. I noticed that the version date string in the xmlns was different in Fenton's example to the one that I'm using. When I changed it to match, it all worked perfectly. Sorry for the confusion! Kev Edited January 26, 2009 by Guest
Fenton Posted January 26, 2009 Posted January 26, 2009 Roy, you have to specify whatever namespaces were defined as belonging to the result in your stylesheet, define a prefix for them (of your own choosing), then exclude them from the result. Yes, it's kind of confusing. But not that hard to do. You can generally ignore the "xsi" and "xsd" ones; these are more for "schema" validation (which is usually optional; they are more if you wanted to see what the possible elements and options were).* But I don't really know all the specifics, other than that's kind of what they're about. Include them in the stylesheet, but you don't have to define a prefix for them. You cannot ignore the plain "xmlns" (xml namespace) however. *Kind of like FileMaker's Field definitions & options. So the main one (from what I can see) is: xmlns="urn:yahoo:lcl" That could be matched with a styesheet using this: xmlns:yah="urn:yahoo:lcl" exclude-result-prefixes="yah"> Then each element you wanted to match in the xml would need to be prefixed with my (dumb) "yah" prefix, like this (from a geocode example).
beverly Posted February 4, 2009 Posted February 4, 2009 Sometimes the namespace will give you a clue what to use for the "shortcut", othertimes you create your own. As Fenton says, it just has to be UNIQUE. Then all the elements used by the namespace get called with it. Think of it as a "path" to the description of the element. It may not be a *real* URN/URL, but it matters!
Recommended Posts
This topic is 5769 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now