Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML What is XML? Why do I need it? How do I use it?

Similar presentations


Presentation on theme: "XML What is XML? Why do I need it? How do I use it?"— Presentation transcript:

1 XML What is XML? Why do I need it? How do I use it?

2 What is XML? XML – extensible markup language. A well-formed, parsable language able to convey structured textual data. A meta language for defining hierarchical markup languages

3 Sample XML – – Java for programmers – Java for morons –

4 How do I spec correct xml? You don’t have to (the parser is tolerent of bad xml) You can do syntax checking on parsing using –The old way DTD –The new way XML Schema (is xml for defining xml!).

5 DTD’s Document Type Defn Language <!DOCTYPE nameOfItem [ elements follow ]>

6 Doing the DOCType <!DOCTYPE Cart [ ]> ….products

7 Shopping Cart Image Processing in Java $45.00 ….more stuff

8 Read XML Build an XML reader for reading HTML!

9 writeXml xml.utils has: public static void writeXml(Serializable object) { XMLEncoder e = new XMLEncoder( futils.Futil.getFileOutputStream("select xml output file")); e.writeObject(object); e.close(); }

10 readXml public static Object readXml() { XMLDecoder e = new XMLDecoder(Futil.getFileInputStream("sel ect an xml file")); return e.readObject(); }

11 xml.Utils public static String toXml(Serializable object) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder e = new XMLEncoder(baos); e.writeObject(object); e.flush(); return baos.toString(); }

12 Preferences package: java.util.prefs.Preferences store and retrieve user and system data. available since jdk1.4 putByteArray(java.lang.String key, byte[] value)java.lang.String public byte[] getByteArray(java.lang.Strin g key, byte[] def)java.lang.Strin g def=default value

13 What good is putting out bytes? serializable objects compression can be employed store images, audio, multi-media, etc.

14 Why would you want anything else? Might be good to stash XML Human readable text Good for testing/debugging

15 How do I store strings? void put(java.lang.String key, java.lang.String value)java.lang.String java.lang.String get(java.lang.String key, java.lang.String def)java.lang.String def – default value

16 how do I get the user Prefs? static Preferences userRoot() Returns the root preference node for the calling userPreferences

17 How do I get the system prefs? public static Preferences systemRoot() Returns the root preference node for the system.Preferences

18 Example of getting user data private static String getData() { Preferences p = Preferences.userRoot(); return p.get("com.docjava.foo", null); }

19 Example of Writing user data private static void putData(String s) { Preferences p = Preferences.userRoot(); p.put("com.docjava.foo", s); } check futils.PreferencesExample

20 How do you set up the prefs?

21 Using the WebstartDialog In the security package, use Preferences to serialize an xml version of the webstartdialog….so that next time you start, the old values are retained. Use the user’s preferences. add an xmlDecoder in the WebStartBean The bean has the values…the dialog is the gui.


Download ppt "XML What is XML? Why do I need it? How do I use it?"

Similar presentations


Ads by Google