忽略 E4X 节点名称和属性的大小写?
有谁知道忽略 XML 节点名称和属性上的大写/小写/驼峰式大小写的技巧吗?
一个简单的例子:我向客户端提供了一个 XML 文件,其中包含名为 fooID 的 XML 属性,但客户端可以更改 XML,并且 - 不知道大小写更改或在“fooid”下添加属性。当然,我的解析器(在 AS3 中)会忽略全小写的属性。请注意,fooID 中包含的值不是这里的问题,而是属性名称本身。有什么想法吗?
Does anyone know of a trick to ignore upper/lower/camelcase on XML node names and attributes?
A quick example: I give an XML file to my client which contains an XML attribute named fooID but the client could change the XML, and - not being aware of upper/lowercaseness change or add an attribute under 'fooid'. Naturally my parser (in AS3) would ignore the all lowercase attribute. Note that the value contained in fooID isn't the problem here but the attribute name itself. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 xml 查询中使用 RegExp,并使其不区分大小写
const list:XMLList = xml.*.(@name.toString().search( new RegExp("hello", "i") )!= -1);
use RegExp in your xml query, and have it case insensitive
const list:XMLList = xml.*.(@name.toString().search( new RegExp("hello", "i") )!= -1);
您可以编写自己的 XML 解析器(E4X 之前的旧方式),其中递归地循环遍历所有节点,查找您选择的节点名称,然后写出对象图或以其他方式存储解析后的 XML 。这涉及根据任何允许的节点名称测试每个节点名称(伪代码:
if nodename == "fooID" then do some things with the node
)。因为您要在每个节点上进行 iffing,所以您可以通过小写节点名和“fooID”来标准化匹配。虽然麻烦,但确实有窍门。
You could write your own XML parser (the old, pre-E4X way), in which you loop through all nodes recursively, look for the node names of your choice, and then write out an object graph or store the parsed XML in other ways. This involves testing each node name against any allowed node name (pseudo code:
if nodename == "fooID" then do something with the node
). Because you're iffing on each node, you can normalize the matching by lowercasing both nodename and "fooID".Cumbersome, but does the trick.
这似乎对我有用:
This seems to work for me: