Thread: Loading data through an XML File.

Results 1 to 7 of 7
  1. #1 Loading data through an XML File. 
    Donator

    Ecstasy's Avatar
    Join Date
    Sep 2008
    Age
    29
    Posts
    5,031
    Thanks given
    324
    Thanks received
    596
    Rep Power
    843
    Basically I saw some kid posting on how to load data through .txt files, so I thought I'd post how to do it through XML.

    This has probably been posted before but I haven't seen anything, so don't flame me.

    Okay, first of all - the methods. Add these anywheres, I don't care.

    Code:
    public void LoadProperties(String property1, String property2) {
            LoadProperties lp = new LoadProperties();
            try {
                Properties properties = lp.readXmlProperties("yourfile.xml");
                properties.list(System.out);
                String data1 = properties.getProperty(property1);
                System.out.println(data1);
                String data2 = properties.getProperty(property2);
                System.out.println(data2);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public Properties readXmlProperties(String file) throws Exception {
            Properties properties = new Properties();
            FileInputStream f = new FileInputStream(file);
            properties.loadFromXML(f);
    
            return properties;
        }
    Usage:
    Code:
    LoadProperties("data1", "data2");
    Also don't forget to fill out the "yourfile" part.

    Basically just read through that, you will get the hang of it. Now here is the XML file.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
    <properties>
      <comment>Comment.</comment>
      <entry key="data1">Data1 Entry</entry>
      <entry key="data2">Data2 Entry</entry>
    </properties>

    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Dec 2007
    Age
    32
    Posts
    551
    Thanks given
    0
    Thanks received
    2
    Rep Power
    503
    Not really good to use, properties.loadFromXML uses DOM. Its slower then XStream.

    Good i suppose if you want to be lazy and not l2 load external library's for XStream lawl.
    Reply With Quote  
     

  3. #3  
    Ikram
    Guest
    Mines better kid.
    Reply With Quote  
     

  4. #4  
    Donator

    Ecstasy's Avatar
    Join Date
    Sep 2008
    Age
    29
    Posts
    5,031
    Thanks given
    324
    Thanks received
    596
    Rep Power
    843
    Cool story bro, now gtfo.

    Reply With Quote  
     

  5. #5  
    ⚓Manic-Owner⚓


    Join Date
    Nov 2007
    Posts
    2,711
    Thanks given
    47
    Thanks received
    9
    Rep Power
    650
    What's the best way to load files fastest and most efficient. I heard xml...?
    MY DISCORD:
    bluejay#1504
    Reply With Quote  
     

  6. #6  
    Registered Member
    Shamon King's Avatar
    Join Date
    Aug 2007
    Posts
    3,335
    Thanks given
    90
    Thanks received
    228
    Rep Power
    1363
    Probably binary or mysql.
    Reply With Quote  
     

  7. #7  
    Donator

    Ecstasy's Avatar
    Join Date
    Sep 2008
    Age
    29
    Posts
    5,031
    Thanks given
    324
    Thanks received
    596
    Rep Power
    843
    Quote Originally Posted by HardStyle View Post
    Probably binary or mysql.
    Yee what he said.

    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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