---
title: "FLEX读取带有xmlns命名空间的xml"
author: "xlaohe1"
date: "2011-09-28T10:15:52Z"
tags: ["flex xml xmlns"]
categories: ["互联网"]
slug: "flex-xmlns-xml"
draft: false
lastmod: "2011-09-28T10:15:52Z"
id: 1182198
url: "https://namas.iteye.com/blog/1182198"
---

带名字空间的XML \[code="xml"] 张三 23 1984-02-21 zhangsan@hotmail.com \[/code] 不带名字空间的XML \[code="xml"] 张三 23 1984-02-21 zhangsan@hotmail.com \[/code] 读取方式示例 \[code="xml"] var gXml:XML = XML(event.result); trace(gXml); //输出整个XML var ns:Namespace = new Namespace("http://xspf.org/ns/0/"); trace(gXml.ns::users.ns::user.ns::user\_name.toString()); //输出带名字空间的XML trace(gXml.users.user.user\_name.toString()); //输出不带名字空间的XML \[/code] Namespaces翻译为名字空间。是为了防止XML中的标签冲突的，如果XML中定义了xmlns，读取的时候就要用“名字空间::子标签”的方式来读取值。 注意：读取标签里的属性里不能使用名字空间。 例如读取ns::user标签里的id属性，不能写成ns::user.ns::@id，应该直接写成ns::user.@id。 转自：\[url]http://www.cnblogs.com/kaixuan/archive/2009/10/20/1587013.html\[/url]