页面code:
<mx:MenuBar id="myMenuBar" labelField="@label" width="100%">
        <mx:XMLList>
            <menuitem label="MenuItem A">
                <menuitem label="SubMenuItem A-1" enabled="false"/>
                <menuitem label="SubMenuItem A-2"/>
            </menuitem>
        </mx:XMLList>
</mx:MenuBar>
我想取到myMenuBar 的属性width的值. 看了API试验了很多次都没有找到怎么做,各位求救啊!

解决方案 »

  1.   

    jdom 一个示例
      

  2.   

    <?xml version="1.0" encoding="gb2312"?>
    <books>
       <book email="zhoujunhui">
         <name>rjzjh</name>
         <price>60.0</price>
      </book>
    </books>
    public class JDomParse {
    2 public JDomParse(){
    3 String xmlpath="library.xml";
    4 SAXBuilder builder=new SAXBuilder(false);
    5 try {
    6 Document doc=builder.build(xmlpath);
    7 Element books=doc.getRootElement();
    8 List booklist=books.getChildren("book");
    9 for (Iterator iter = booklist.iterator(); iter.hasNext();) {
    10 Element book = (Element) iter.next();
    11 String email=book.getAttributeValue("email");
    12 System.out.println(email);
    13 String name=book.getChildTextTrim("name");
    14 System.out.println(name);
    15 book.getChild("name").setText("alterrjzjh");
    16
    17 }
    18
    19 XMLOutputter outputter=new XMLOutputter();
    20 outputter.output(doc,new FileOutputStream(xmlpath));
    21
    22 } catch (JDOMException e) {
    23 e.printStackTrace();
    24 } catch (IOException e) {
    25 e.printStackTrace();
    26 }
    27 }
    28 public static void main(String[] args) {
    29 new JDomParse();
    30 }
    31}(6)取得元素的属性:
        String email=book.getAttributeValue("email");
       取得元素book的属性名为“email”的属性值。
      

  3.   

    建议lz用 dom4j 用XPath搜索你想要的节点或属性,对于XPath的文章网上大把了,而去很容易使用和学习
      

  4.   

    不好意思,忘记说了是在FLEX运行环境中,在actionscript中虽然可以取得myMenuBar 对象和他的子对象等,但是就是没有找到取width属性的API
    本来本贴发在flex版的,可惜那里没有兄弟回答,现在这里这么多朋友帮忙很感谢,请知道的朋友多给意见