Attribute value not displaying?

Help
2012-11-05
2013-05-01
  • Verhaag, G.C.H.M.

    Hi,

    I'm trying to write a plugin to carry out particular actions on a project selected from the XML file.

    Each project tag has two attributes.

    Part of the plugin looks like below:

                         

                           Document ddoc = doc.DOMdoc;
                           NodeList nodeList=ddoc.getElementsByTagName("project");
                   Element project = (Element)(nodeList.item(1));
    
                   NamedNodeMap nnm = project.getAttributes();
                           String attrs = "";
                for (int i=0; i<=nnm.getLength(); i++) {
                    Attr ndAttr = (Attr) nnm.item(i);
                }
    
                JOptionPane.showMessageDialog(doc.jframe,
                    project.getNodeName(), "ProjectsStats", JOptionPane.INFORMATION_MESSAGE);
    

    Everything works as expected; the NodeName is shown correctly in the dialog message. However when I add
    the following within the for-loop:

    String val = ndAttr.getValue();
    

    to get the value of each attribute, the message dialog is not popping up any more? I use java 1.7.0_05 to compile!
    (This is of course not the final plugin, but just for testing things!)

    Any idea what is causing this strange behaviour?

    Regards,
    verhaaggchm

     
  • Damien Guillaume

    I don't know, but you might want to find ways to get more error messages. Did you check .jaxe.log ? You could also run jaxe from the command line to get more error messages.

    Also, did you really mean to select the second project element ?

    Finally, I would recommend using the NS methods in the DOM API. They handle namespaces, and Jaxe is using them. I'm not sure mixing NS and non-NS methods is working well.

     
  • Verhaag, G.C.H.M.

    Hi,

    Thanks for your answer and tip! Yes, I checked the log file, no error indications. I also did a System.out.println of the attribute value and it showed the correct value.

    Yes, I did mean to select the second project!

    When using the for example getNamedItemNS method of the DOM API, as you suggested, the message dialog popped up again and showed the correct attribute value. So, the use of the NS methods is critical!

    Regards,
    verhaaggchm

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks