Xml 如何知道属性或节点是否具有不同的命名空间?
如何知道何时遇到具有名称空间的节点,以及何时可以提取该名称空间的名称和URL XML:Xml 如何知道属性或节点是否具有不同的命名空间?,xml,actionscript-3,flash,Xml,Actionscript 3,Flash,如何知道何时遇到具有名称空间的节点,以及何时可以提取该名称空间的名称和URL XML: 我可以在字符串中检查::,但这似乎很麻烦。一定有更好的办法 使用来自不同但相关帖子的信息,我能够检查attribute.namespace对象。通常这没什么!但当它具有名称空间前缀时,它将返回一个对象 public static function getAttributeNames(node:XML):Array { var result:Array = []; var attributeNa
我可以在字符串中检查::,但这似乎很麻烦。一定有更好的办法 使用来自不同但相关帖子的信息,我能够检查attribute.namespace对象。通常这没什么!但当它具有名称空间前缀时,它将返回一个对象
public static function getAttributeNames(node:XML):Array {
var result:Array = [];
var attributeName:String;
for each (var attribute:XML in node.attributes()) {
attributeName = attribute.name().toString();
var attNamespace:Object = attribute.namespace();
var a:Object = attribute.namespace().prefix //returns prefix i.e. rdf
var b:Object = attribute.namespace().uri //returns uri of prefix i.e. http://www.w3.org/1999/02/22-rdf-syntax-ns#
var c:Object = attribute.inScopeNamespaces() //returns all inscope namespace as an associative array like above
//returns all nodes in an xml doc that use the namespace
var nsElement:Namespace = new Namespace(attribute.namespace().prefix, attribute.namespace().uri);
var usageCount:XMLList = attribute..nsElement::*;
result.push(attributeName);
}
return result;
}
从中获得的信息
public static function getAttributeNames(node:XML):Array {
var result:Array = [];
var attributeName:String;
for each (var attribute:XML in node.attributes()) {
attributeName = attribute.name().toString();
result.push(attributeName);
}
return result;
}
trace (result);
[0] visible
[1] library://ns.test.com/flex/::locked
public static function getAttributeNames(node:XML):Array {
var result:Array = [];
var attributeName:String;
for each (var attribute:XML in node.attributes()) {
attributeName = attribute.name().toString();
var attNamespace:Object = attribute.namespace();
var a:Object = attribute.namespace().prefix //returns prefix i.e. rdf
var b:Object = attribute.namespace().uri //returns uri of prefix i.e. http://www.w3.org/1999/02/22-rdf-syntax-ns#
var c:Object = attribute.inScopeNamespaces() //returns all inscope namespace as an associative array like above
//returns all nodes in an xml doc that use the namespace
var nsElement:Namespace = new Namespace(attribute.namespace().prefix, attribute.namespace().uri);
var usageCount:XMLList = attribute..nsElement::*;
result.push(attributeName);
}
return result;
}