Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2012, 01:06 PM
Smuck Smuck is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 Smuck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 13 sec
Reputation Power: 0
Swing - Traversing XML data very slow/never ends

For some reason a command line tool is much quicker at saving data to a file.xml rather than returning data through standard output.

So it's instructed to save a data.xml file which is then parsed to a Document variable in java. And this happens in a few seconds.

But then when traversing the Document to put all data in a String it never finish. This is just meant to test traversing. The string result is not needed.
Code:
    public static String xmlToString(Node xmlDoc) {
        String xmlStr = "\nNode " + xmlDoc.getNodeName() + "\nValue" + xmlDoc.getNodeValue() + "\nText" + xmlDoc.getTextContent() + "\ntoString" + xmlDoc.toString() + "\n";
        
        // Now traverse the rest of the tree in depth-first order.
        if (xmlDoc.hasChildNodes()) {
            // Get the children in a list.
            NodeList nl = xmlDoc.getChildNodes();
            // How many of them?
            int size = nl.getLength();
            for (int i=0; i<size; i++) {
                // Recursively traverse each of the children.
                xmlStr += xmlToString(nl.item(i));
            }
        }
        return xmlStr;
    }

Reply With Quote
  #2  
Old November 9th, 2012, 02:04 PM
Smuck Smuck is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 Smuck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 13 sec
Reputation Power: 0
Tried altering traverser, but it's still stuck
Code:
    public static String xmlToString(Node xmlDoc) {
        String xmlStr = "\nNode " + xmlDoc.getNodeName() + "\nText:" + xmlDoc.getTextContent() + "\n";
        if (xmlDoc.hasChildNodes()) {
            xmlStr += xmlToString(xmlDoc.getFirstChild());
        }
        if (xmlDoc.getNextSibling() != null) {
            return xmlStr + xmlToString(xmlDoc.getNextSibling());
        }
        return xmlStr;
    }

Reply With Quote
  #3  
Old November 9th, 2012, 02:11 PM
NormR's Avatar
NormR NormR is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,958 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 3 h 7 m 10 sec
Reputation Power: 345
Can you make a small, simple program that compiles, executes and shows the problem?

Reply With Quote
  #4  
Old November 10th, 2012, 04:54 AM
Smuck Smuck is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 Smuck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 13 sec
Reputation Power: 0
Quote:
Originally Posted by NormR
Can you make a small, simple program that compiles, executes and shows the problem?
The code is broken up in different files (Netbeans - latest version).

I'm trying to use the command line tool MP4Box to get information about a media file. With -diso it dumps the file structure in .xml . With -std -diso it returns the data but it takes much longer.

So this code retrieves xml from file and it takes a few secs:
Code:
    public String MP4BoxSend(String arg) {
        Runtime rt = Runtime.getRuntime();
        String line, output = "";
        try {
            Process pr = rt.exec("mp4box\\MP4Box.exe " + arg);
            BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            while ((line = input.readLine()) != null) {
                output += "\n" + line;
            }
            int exitVal = pr.waitFor();
        } catch(IOException | InterruptedException e) { 
            JOptionPane.showMessageDialog(null, e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        return output;
    }

    Document MediaXml;
    
    public String MP4BoxGetMediaInfo(String file_name) {
        String arg = "-diso \"" + file_name + "\""; // Dump Media Info in XML file
        String Error = MP4BoxSend(arg);

        String XmlFilename = ExtendedString.removeExt(file_name) + "_info.xml";
        File file = new File(XmlFilename); // Connect to dumped xml file
        if (file.exists()) {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db;
            try {
                db = dbf.newDocumentBuilder();
                MediaXml = db.parse(file);
            } catch (ParserConfigurationException | SAXException | IOException ex) {
                Logger.getLogger(MP4Box.class.getName()).log(Level.SEVERE, null, ex);
            }
            file.delete();
        }
        return Error;
    }
And this code calls method that is supposed to traverse xml and output it in string just so I can see traversing works:
Code:
            MP4Box mb = new MP4Box();
            String MP4BoxError = mb.MP4BoxGetMediaInfo(file_name);
            jTextAreaSource.append("\nXML file parsed! " + MP4BoxError + "\nWill now print out: ");
            jTextAreaSource.append("\n" + ExtendedString.xmlToString(mb.MediaXml));

Reply With Quote
  #5  
Old November 10th, 2012, 07:06 AM
NormR's Avatar
NormR NormR is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,958 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 3 h 7 m 10 sec
Reputation Power: 345
How do I compile and test the code to see the problem? You haven't posted all the code needed for testing.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Swing - Traversing XML data very slow/never ends

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap