Question

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 ?

Was it helpful?

Solution

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");

OTHER TIPS

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.

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

<root xmlns:aws="some-uri">
  <aws:elementname />
</root>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top