English 中文(简体)
Ignoring case on E4X node names and attributes?
原标题:

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?

问题回答

use RegExp in your xml query, and have it case insensitive

const list:XMLList = xml.*.(@name.toString().search( new RegExp("hello", "i") )!= -1);

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:

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




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签