0

Using Xml to parse an XML document in Google Apps Script : http://code.google.com/googleapps/appsscript/articles/XML_tutorial.html#HowItWorks

But this doesn't work (parse fails) if there is a colon in the element name. Even though it maybe the namespace, its a single namespace throughout the XML document.

<aws:elementname>...</aws:elementname>

Is this is an issue only with the google's Xml or is it generic ?

Eric Koleda
  • 12,420
  • 1
  • 33
  • 51
anjanesh
  • 3,771
  • 7
  • 44
  • 58
  • From the documentation I gather that it's namespace-aware. What's the question - whether XML allows colons in element names apart from namespaces? –  Nov 27 '10 at 21:06
  • If google's Xml Class is namespace-aware then it should not have failed parsing. I took the same example "Oracle of Bacon" and added (prepended to each element) aws: to all elements and it failed. – anjanesh Nov 27 '10 at 21:13
  • When you added aws: did you add a namespace declaration for it as well? – Don Roby Nov 28 '10 at 11:29
  • This XML is actually Amazon's AWIS which starts with : dba0a88b-e8fd-d5fc-0040-ee562a127e33 – anjanesh Nov 29 '10 at 05:08

3 Answers3

1

Just don't send argument as true.

var oXML = Xml.parse(sXML, false);
var root = oXML.getElement();
var topElement = root.getElements("http://namespace-uri","topElement");
var childElement = topElement[0].getElements("http://namespace-uri","childElement");
anjanesh
  • 3,771
  • 7
  • 44
  • 58
0

It is definitely not a general issue. There certainly are XML parsers that handle namespaces.

I suspect it's a limitation of the tutorial code and that the google libraries actually can handle namespaces, but it's somewhat guesswork from looking at the API docs.

The tutorial code is using calls like

var movies = doc.html.head.getElements("movie");

which seems to be a non-namespace-aware version.

There is an overload of this method that takes a namespace URL as well, and which you might need to use if there's a namespace involved.

Don Roby
  • 40,677
  • 6
  • 91
  • 113
  • "There is an overload of this method that takes a namespace URL as well, and which you might need to use if there's a namespace involved" - This fails at the parse level. var oXML = Xml.parse(content); – anjanesh Nov 28 '10 at 08:25
0

If you want to use some namespace, you have to first declare it. E.g.:

<root xmlns:aws="some-uri">
  <aws:elementname />
</root>
svick
  • 236,525
  • 50
  • 385
  • 514