使用包含冒号/名称空间的元素解析XML [英] Parsing XML with elements containing colon / namespace

查看:92
本文介绍了使用包含冒号/名称空间的元素解析XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Xml解析Google Apps脚本中的XML文档:
http://code.google.com/googleapps/appsscript/articles/XML_tutorial.html#HowItWorks

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

但这不起作用(解析失败)如果元素名称中有冒号。
尽管它可能是命名空间,但它在整个XML文档中都是单个命名空间。

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>

这只是谷歌的Xml问题还是通用的?

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

推荐答案

只要不发送参数为真。

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

这篇关于使用包含冒号/名称空间的元素解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆