Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- public class XmlParser {
- private static final String[] COLUMNS = new String[] { "Last", "First", "Middle", "Title", "Department", "Location",
- "Phone", "Email" };
- private static final String[] LINES = new String[] {
- "Amodeo,Paul,A,Professor,Business & Information Technology,Warner Hall,518-255-5384,[email protected]",
- "Yacobucci,Kelly,R,First Year Experience Coordinator,School of Business | Lib Arts & Sci,Frisbie Hall 110,518-255-5460,[email protected]",
- "Fisher,James,D,Visiting Instructor,Business & Information Technology,Warner Hall 101,518-255-5826,[email protected]",
- "Schwarzenegger,Karl,F,Associate Professor,Business & Information Technology,Warner Hall,518-255-5693,[email protected]",
- "Luria,Patricia,L,Adjunct Instructor,Liberal Studies,Frisbie 300,518-255-5760,[email protected]",
- "Eldred,Melody,E,Professor,Natural Sciences & Mathematics,Frisbie Hall 101,518-255-5116,[email protected]",
- "Begany,Grace,M,Assistant Professor 10 Months,Business & Information Technology,Warner Hall,518-255-5273,[email protected]", };
- public static void main(String[] args) throws IOException {
- XmlParser parser = new XmlParser();
- StringBuilder xml = new StringBuilder("<Directory>\n");
- for (String line : LINES) {
- String record = parser.parse(line);
- xml.append(record).append("\n");
- }
- xml.append("</Directory>");
- System.out.println(xml);
- }
- private String parse(String commaSeperated) {
- String[] data = commaSeperated.split("\\s*,\\s*");
- StringBuilder xml = new StringBuilder("\t<Faculty>\n");
- for (int id = 0; id < data.length; id++) {
- StringBuilder tag = new StringBuilder("<" + COLUMNS[id] + ">");
- xml.append("\t\t").append(tag).append(data[id]).append(tag.insert(1, "/")).append("\n");
- }
- xml.append("\t</Faculty>");
- return xml.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement