忽略 E4X 节点名称和属性的大小写?

发布于 2024-08-19 09:11:05 字数 208 浏览 5 评论 0原文

有谁知道忽略 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

琉璃繁缕 2024-08-26 09:11:05

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

雾里花 2024-08-26 09:11:05

您可以编写自己的 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.

此刻的回忆 2024-08-26 09:11:05

这似乎对我有用:

var lowerCasePropertyName:String = propertyName.toLowerCase();
var xmlItem:XMLList = xml.*.(attribute("name").toString().toLowerCase()==lowerCasePropertyName);

This seems to work for me:

var lowerCasePropertyName:String = propertyName.toLowerCase();
var xmlItem:XMLList = xml.*.(attribute("name").toString().toLowerCase()==lowerCasePropertyName);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文