What's a good way to show attributes in a JTree made from DOM?

I'm doing a pretty simple project that's basically just taking an XML document, making a DOM out of it, and then I want to represent the document in a JTree. The code I have now works swimmingly, except it doesn't do anything about attributes. Ideally (for the purposes of the tree), I'd like the attributes to show up as children of the node of which they are an attribute, and then each attribute node would itself have a child representing the value.
basically I want to go from this:
<xmlNode attribute=value>
   <child>
   </child>
</xmlNode>To a JTree like this ('v' being the expansion arrow on the tree):
v xmlNode
   v attribute
      v value
   v childI realize they're not of equivalent meaning, but for my purposes representing the true structure of the XML is not as important as meaningfully representing the information it contains.
My question is basically, is there a more straightforward way to accomplish this than to manually add children nodes for all of the attributes? How would you approach this problem? I'm not looking for code or for someone to give me the "answer," I just wanted to get a second opinion.

camickr and DrClap, thanks for your ideas! Both of those solutions seem pretty reasonable for what I'm doing, I'll experiment with them (I do indeed already have a custom Tree model, so adding this in wouldn't actually be too difficult... I don't know why that didn't occur to me!).
Thanks for the replies!

Similar Messages

  • What's a good way to manage custom schema for DS  5.1?

    What's a good way to manage custom schema?
    Custom Schema for Object Class and Attributes
    The reason I ask this is because there might be a need in the future where I need to export those custome schema into different branded directory server. I just want to make this as painless as possible.
    Right now, I thought of 2 options
    1) Create my own LDIF file with my custom attributes and object classes, so if one day I need to export to another directory server, I can just copy that custom created LDIF file over. (Will this work?)
    2) Create a JAVA application using JNDI. What this Java App. will do is read through a XML file and create those object classes and attributes on-the-fly. (of course, the XML structure will be predefined by me, so that my Java App. will be able to parse through it correctly. Will this work?)
    Anymore suggestion? I would want to hear more advices and suggestions.
    Also, I assume that will work even with replication. All I need to update is the master server, and the slaves will replicate automatically.
    Thank you very much! :)

    Demo: I'm using the nul character to represent the end of the word, so that the data structure can represent that "hell" and "hello" are both in the vocabulary:
    import java.util.*;
    class Node {
        private SortedMap<Character, Node> children = new TreeMap<Character, Node>();
        //0 <= index <= word.length()
        private void add(String word, int index) {
            if (index == word.length()) {
                children.put(Character.valueOf('\u0000'), null);
            } else {
                char ch = word.charAt(index);
                Node child = children.get(ch);
                if (child == null) {
                    children.put(ch, child = new Node());
                child.add(word, index+1);
        public void add(String word) {
            if (word == null || word.length()==0)
                throw new IllegalArgumentException();
            add(word, 0);
        public String toString() {
            return children.toString();
    public class Example {
        public static void main(String[] args) throws Exception {
            Node root = new Node();
            root.add("hello");
            root.add("how");
            root.add("who");
            root.add("hell");
            System.out.println(root.toString());
    }

  • What are the good ways to send a big file( 20MB-100MB) file to my friend?

    what are the good ways to send a big file( 20MB-100MB) file to my friend?
    Thanks in advance

    if this is with the internet, iChat is probly your best bet,
    but if you just want a transfer,
    plug a firewire into both of your computers, shutdown one of them, hold "T" and press the power button, the restarted computer should pop up as an external drive on the second computer.

  • What's a good way to do a thread dump into a separate file

    What is a good way to do a thread dump automatically into a separate file.
    Example. I run a script to do the thread dump, but unfortunetly, it goes into my stdout log file with the rest of my weblogic errors.
    Any ideas? I want it in a separate file when I run my script?

    Do a Google search on "Drobo S" "benchmark."  I don't have a Drobo S, only the regular Drobo.  But here's a guy who tested one on Windows:
    http://mansurovs.com/drobo-s-review-usb-3-0-2nd-generation
    This one has it a bit faster:
    http://the-gadgeteer.com/2011/12/31/drobo-s-storage-array-review/
    Do read up on a few reviews of it, and be absolutely clear that interface speed (i.e. eSATA versus Firewire versus Thunderbolt) is NOT the same as the performance of the system.  The Drobo cannot keep up with any interfaces... at least the Drobo and the Drobo S cannot.
    I am not using the FS model which is a NAS.  I am using the plain old "Drobo" which is slower than the Drobo S, but that's not to say that the Drobo S is fast, because it is not.
    The Drobo in theory is really attractive: Dead simple to manage, can mix and match drive sizes, offers you some data protection, etc.  However do note that protected storage is not, in and of itself, a backup.  You need other backups besides just the data on the Drobo.  And, because it's so slow, it's really not a great fit for photo storage.  See this review from a guy who used to think the Drobo was great for that and then appended his review:
    http://www.stuckincustoms.com/drobo-review/
    To be as clear as possible, IMO the BEST backup strategy with something like Aperture (so long as your managed Aperture library is of a manageable size, like < 800 GB), is to get a few small portable Firewire 800 drives and keep vaults on each one.  They are great because they are easy to use, to have with you, are bus powered, and you WILL offsite them.

  • What is a good way to load 80 million documents in DocumentDB?

    I am having problems loading a large set of data.  We want to load 80 million documents.  We are trying to do testing for an IOT solution that will end up having a lot of data in it.  I followed the instructions to use a stored procedure to
    do a bulk load provided by Ryan CrawCour on the Microsoft Site:
    https://code.msdn.microsoft.com/windowsazure/Azure-DocumentDB-NET-Code-6b3da8af
    But it throws exceptions when we load 2,000 - 5,000 documents.  Our documents are only about 80 characters.
    Error: One or more errors occurred., Message: Exception: Microsoft.Azure.Documen
    ts.RequestRateTooLargeException, message: {"Errors":["Request rate is large"]},
    What is a good way to load large datasets?  ( Load backups, migrate data, ... )  Or is DocumentDB just a wrong choice when you have millions of rows to load?
    Thanks

    Hi,
    I had been working on this from around one month and I am happy to say that my code works. Was able to upload around 0.5 million documents in 20 min. 
    The configuration was Document DB with S3 , I scaled out for 16 collection for sharding, I think you need to shard out more. This will depend on how much each document takes.
    So the Calculation goes like if each document is lets say on an average 2Kb of Size and you have 80 million documents that will come out to be 160GB
    That means you will need more than 16 collections to store as at Max 1 collection can have 10GB of Data. So to be on the safer side I would say lets go for 3 times the storage so 48 collections . If all of them are at S3 than you have 2500 RUs spread across
    48 collections and I am sure if you do insertion now you will not get Request Rate too large exception.
    I have come up with this code hopefully it will help you as well.
    https://social.msdn.microsoft.com/Forums/azure/en-US/d036afe2-78ec-45ee-8b0d-297f0f5320fe/azure-documentdb-bulk-insert-using-stored-procedure.
    For Sharding you can have look at
    https://msdn.microsoft.com/en-us/library/dn589797.aspx?f=255&MSPPError=-2147217396.

  • What is the good way to charge the battery

    I don't know if this topic been answered before.
    I want to know what is the good way to charge the battery on Macbook pro? Should I start charging battery when it's 50% or 20% or 10% left? and Is it good to leave the charge plug in after it fully charged?
    thanks guys

    Everything you need to know about your battery is explained here:
    http://discussions.apple.com/thread.jspa?threadID=1764220

  • What's the easiest way to show query results?

    I have a button on the Business Partner form, and I want to show the results of a query when you push it.  What's the easiest way to show this data to the user?
    Am I going to have to create a new form and add a matrix to it?  There has to be an easier way.

    Hi Bryan,
    If the query is without parameter, you can activate the menu for this query, else I think the best way is a new form with a grid (much faster than matrix).
    Regards
    Ad

  • I'm buying a new Macbook Pro this week and am wondering what is the best way to copy over the software I have from my existing Macbook Pro to the new one? eg. Photoshop and Office etc. I no longer have the CDs.

    I'm buying a new Macbook Pro this week and am wondering what is the best way to copy over the software I have from my existing Macbook Pro to the new one? eg. Photoshop and Office etc. I no longer have the CDs.

    Ya know what I'm on a brand new MBP just about 24 hours old and you know whats been working amazingly for me. I have a 27inch iMac as well and i've just connected it to my network and been dragging files and apps across the network onto my new MBP. Its really working fast and its flawless. You could always do that option, Just go into sharing options and turn them on for both Macs. Then just click and drag. Of course they have to both be on the same network for this to be possible.
    Look at my network.
    Shared is what your looking at.  I click on there see all my computers files and then drag the ones i want form its folder to my MBP folders.  Hope that helps if your looking for a very simple way on a wireless network.

  • What is the best way to have access to OSX and OS9 from the same machine?

    What is the best way to have access to OSX and OS9 from the same machine?
    Do I need to partition the hard drive? Installed both Tiger and OS 9 on the G5 and it is having problems starting up properly.
    G5   Mac OS X (10.4)  

    And here is the prove for Edwin's message: Macintosh: Some Computers Only Start Up in Mac OS X

  • What is the best way to manage tasks?  I have moved from outlook and only have mail and ical

    What is the best way to manage tasks.  I have moved from a pc with outlook and have lost 'tasks' in that programme.  Do I have to rely on ical or can I download an app to manage business tasks?

    iCal does have reminders but its implementation of tasks is pretty wimpy. There are a number of programs that are better geared to the job. I was a level 4 procrastinator until I discovered Getting Things Done and for me Things is perfect. It lets me handle projects which are dependent upon multiple tasks in a no-nonsense easy fashion. Much less expensive and really not much more than a list maker is Wunderlist. Thankfully there's a ton of shareware offerings - check out MacUpdate.com and see what works for you.

  • What's a good way to dynamically allow shortened commands?

    I have a BufferedReader set up that attaches to System.in.
    so, when I check the BufferedReader, it will retreive any commands put in by a user.
    I will have a hash table for commands set up like so:
    "north", "dn"
    "west", "dw"
    "south", "ds"
    "east", "de"
    "follow", "follow"
    "flee", "flee"
    "flip", "flip"
    So, what I want is to be able to check all the commands and shorten them to the lowest amount of chars before they're the same.
    Therefore, for the example hash list, if I typed in "fle", the code would select "flee". Or, if I typed "fo", the code would select "follow". But, if I typed in "f", then the code would respond with a "command not found" error, because "f" could be follow, flip or flee. I want to make it so that I can type "follow", "follo", "foll", "fol", "fo", and "fo" to select the same "follow" command.
    Has anyone found a good way of going about this? If my description is confusing, I'll try to re-explain in greater detail.

    Demo: I'm using the nul character to represent the end of the word, so that the data structure can represent that "hell" and "hello" are both in the vocabulary:
    import java.util.*;
    class Node {
        private SortedMap<Character, Node> children = new TreeMap<Character, Node>();
        //0 <= index <= word.length()
        private void add(String word, int index) {
            if (index == word.length()) {
                children.put(Character.valueOf('\u0000'), null);
            } else {
                char ch = word.charAt(index);
                Node child = children.get(ch);
                if (child == null) {
                    children.put(ch, child = new Node());
                child.add(word, index+1);
        public void add(String word) {
            if (word == null || word.length()==0)
                throw new IllegalArgumentException();
            add(word, 0);
        public String toString() {
            return children.toString();
    public class Example {
        public static void main(String[] args) throws Exception {
            Node root = new Node();
            root.add("hello");
            root.add("how");
            root.add("who");
            root.add("hell");
            System.out.println(root.toString());
    }

  • What is a good way for a heavy iMovie HD user to learn iMovie'09 ?

    Hi Guys,
    I have been using iMovie HD to edit my videos since mid 2005. I understand that Apple will, sooner or later, stop supporting iMovie HD with updates etc (it may have done so already).
    I'm doing event and safety videos for the company I'm working for. I tried to edit a video in iMovie'08 and found it too different from iMovie HD and it was difficult for me to "unlearn" iMovie HD.
    What would be a good way to learn iMovie '09 ?
    I would appreciate any tips & pointers. Thanks in advance.
    Sincerely,
    Azman

    I think the best way is to jump in and make a movie. If you get frustrated about something you know you should be able to do, there is probably a way to do it and you can ask here.
    Also, there are some [very good video tutorials here|http://www.apple.com/findouthow/movies>
    I recommend you start with the iMovie 08 videos because they cover some of the basics, and Apple has not gotten around to doing some of these topics for iMovie 09. Especially watch the videos for handling audio and keywords. Then watch the iMovie 9 videos.
    The biggest thing is getting used to a different metaphor. iMovie 6 uses the timeline, scotch tape and scissors metaphor, while iMovie 09 uses a storyboard, copy and paste metaphor more like a word processing program. Both metaphors work. Both do the same thing. But it can be frustrating making the switch. Good luck.

  • What is the best way to show/hide n number of columns ?

    Hi,
    I have a dynamic report that I have show/hide columns working using the below code. But when there are 500 or more rows it takes about a minute or more just waiting to see the columns toggle.
    What is the best way to do this?
    // Existing Javascript
    [script language="JavaScript" type="text/javascript"]
    var maxcnt= mymonths.length;
    function hideMaxEarn(){
    for(var j=0;j[maxcnt;j++){
    hideColumn('MON'+mymonths[j],'MAXCOL'+mymonths[j]);
    hideColumn('MON'+mymonths[j],'EARNCOL'+mymonths[j]);
    hideColumn('MON13','MAXCOL13');
    hideColumn('MON13','EARNCOL13');
    function showMaxEarn(){
    for(var j=0;j[maxcnt;j++){
    showColumn('MON'+mymonths[j],'MAXCOL'+mymonths[j]);
    showColumn('MON'+mymonths[j],'EARNCOL'+mymonths[j]);
    showColumn('MON13','MAXCOL13');
    showColumn('MON13','EARNCOL13');
    function getCellIndex(pRow,pCell){ 
    for(var i=0, n=pRow.cells.length;i[n;i++){ 
        if(pRow.cells[i] == pCell) return i;
    function hideColumn(pMon,pCol){
    var l_Cell = $x(pCol);
    var l_Table = html_CascadeUpTill(l_Cell,'TABLE');
    var l_Rows = l_Table.rows;
    l_CellI = getCellIndex(l_Cell.parentNode,l_Cell);
    for (var i=0, n=l_Rows.length;i[n;i++){
        if(i != 0) {
           html_HideElement(l_Rows[i].cells[l_CellI]);
    } else {
    $x(pMon).colSpan = $x(pMon).colSpan - 1;
    function showColumn(pMon,pCol){
    var l_Cell = $x(pCol);
    var l_Table = html_CascadeUpTill(l_Cell,'TABLE');
    var l_Rows = l_Table.rows;
    l_CellI = getCellIndex(l_Cell.parentNode,l_Cell);
    for (var i=0, n=l_Rows.length;i[n;i++){
        if(i != 0) {
           html_ShowElement(l_Rows[i].cells[l_CellI]);
    } else {
    $x(pMon).colSpan = 3;
    return;
    [script]

    Hi Andy,
    Yes, I replaced the code calling the same things in a loop to one loop getting the Table reference once and I build an array of column numbers at the time the report is built so I don't have to get the column number each time....
    it is a couple of seconds faster in about a 30 second response time. It will have to do it for now, no more time unless you see something in this new code...
    Thank you! Bill
    // dynamically built code
    col_nbr_array = new Array();
    col_nbr_array[0] = "1";
    col_nbr_array[1] = "2";
    col_nbr_array[2] = "4";
    col_nbr_array[3] = "5";
    col_nbr_array[4] = "7";
    col_nbr_array[5] = "8";
    col_nbr_array[6] = "10";
    col_nbr_array[7] = "11";
    col_nbr_array[8] = "13";
    col_nbr_array[9] = "14";
    col_nbr_array[10] = "16";
    col_nbr_array[11] = "17";
    col_nbr_array[12] = "19";
    col_nbr_array[13] = "20";
    col_nbr_array[14] = "22";
    col_nbr_array[15] = "23";
    col_nbr_array[16] = "25";
    col_nbr_array[17] = "26";
    col_nbr_array[18] = "28";
    col_nbr_array[19] = "29";
    col_nbr_array[20] = "31";
    col_nbr_array[21] = "32";
    col_nbr_array[22] = "34";
    col_nbr_array[23] = "35";
    col_nbr_array[24] = "37";
    col_nbr_array[25] = "38";
    col_nbr_array[26] = "40";
    col_nbr_array[27] = "41";
    // Static code
    function show_hide_column(do_show) {
    // Set Style, Show/Hide
    var stl;
    var csp;
    if (do_show){
    stl = 'block'
    csp = 3;
    }else{
    stl = 'none';     
    csp = 1;     
    // get rows object
    var l_Rows = document.getElementById('DT_RANGE').rows;
    var totCellNbr1=parseFloat(col_nbr_array[maxcnt-1])+2;
    var totCellNbr2=totCellNbr1 +1;
    var n=l_Rows.length;
    for (var i=0; i[n;i++){
        if(i != 0) { // if not the main header which spans 3 cols when expanded
          // Go through and show/hide each cell
          for(var j=0;j[maxcnt;j++){
              l_Rows[i].cells[col_nbr_array[j]].style.display = stl;
    // Totals
    l_Rows.cells[totCellNbr1].style.display=stl;
    l_Rows[i].cells[totCellNbr2].style.display=stl;
    } else { // row 1 that has Month spelled out - colspan of 3, others has max,earned and score columns for each month.
    var maxhdr = maxcnt/2;
    for(var k=1;k[=maxhdr;k=k+1){
    //alert('Header['+k+']');
    l_Rows[i].cells[k].colSpan=csp;
    // Total column
    //alert('TotHeader['+(maxhdr+1)+']');
    l_Rows[i].cells[maxhdr+1].colSpan=csp;
    [script]

  • What is a good way to transfer files from an old hard drive to a new one.

    I am running low on space on my 80GB hard drive. I want to replace it with a 320GB hard drive. I was wondering what the best way is to transfer all of my files from the 30GB hard drive to my new 320GB hard drive. Not looking for any secure ways. I dont have many important things. Would appreciate help. Thanks.

    HI,
    Freeing space on your Mac OS X startup disk
    Carolyn

  • What is the easiest way to show a command line app in an appletviewer

    I'd like to convert a command line interface application to a small applet, for use in an appletviewer. What is the easiest way to implement this.

    I made something like what you are describing for a text adventure engine. It uses a big text area for output and a small text field for input.
    Here's the code
    public class myApplet extends java.applet.Applet
         implements Runnable
         TextArea output ;
         TextField input ;
    public void init()
              width = this.size().width ;
              height = this.size().height ;
         public void run()
              makeComponents() ;
              while( true ) // loop on + on + on
              try { Thread.sleep( 10 ) ; }
                        catch (InterruptedException e) {}
    public void makeComponents()
              input = new TextField() ;
              input.setSize( Math.min( 200, width - 5 ), 25 ) ;
              input.setLocation( 5, height - 30 ) ;
              add( input ) ;
              input.addActionListener( new ActionListener()
                   public void actionPerformed( ActionEvent e )
                        String temp = input.getText() ; // do something with this
              output = new TextArea( "", 0, 0, TextArea.SCROLLBARS_VERTICAL_ONLY) ;
              output.setSize( width - 10, height - 40 ) ;
              output.setLocation( 5, 5 ) ;
              add( output ) ;

Maybe you are looking for

  • Itunes wont open. itunes has stopped working message Please help!!

    I had itune 10.1 working just normal, and suddenly it wont open.    even before that, 1st problem i had  was with Quick time, i couldnt uninstall it, kept saying newer version of Quick time installed..or something like that. and i figured out to inst

  • File adapter validate file checking directory for files

    Hi Gurus, We have requirement. There are 3 directories (Processing, Error and Archive)in the Source side.SAP PI need to pick up a file called "abc.txt" from the processing tab. But there is a condition. 1. If "abc.txt" file exists in the "Error" dire

  • How can I get my iBook on the feature page?

    Is there a fee or way to be on the feature page of iBooks?

  • Proxy doesn't work fine with IExplorer

    Hi, I've wrote a proxy using java and now I have a problem when running this proxy on linux and the browser is IE 5.5 or less. The problem is like this. When a POST is made, Request arrives to Proxy , it sends it to server then receives the response

  • Re: Why can't I use a Movers Coupon on a MacBook

    I am now having the exact same issue with the Atlanta - Buckhead store.  I tried messaging Allan directly but haven't gotten a response.  Is there another Best Buy representative that can help me?