Parsing XML
in
Contributed Library Questions
•
2 years ago
Hello. I am entirely new to Processing as of Wednesday. I am preparing an installation for class that will pull posts from a blog, randomize the sentence structure and display them. My coding may not be up to par as I am so new, but I have a quick question.
I am trying to parse the <title> data from the xml on the blog I am pointing at and write it to "sourcefile.txt." So far all that the program will write to the file is "[<title>, <title>, <title>]." I'm not really sure about how to pull the text out from in between the title tags and I am having a rough time here as a newbie. Ideally I would like the titles alone to be displayed in this manner "Lets write a story together. Test."
Let me know if you can help!
Thanks :)
- import prohtml.*;
- HtmlList htmlList;
- int wrap = 60;
- PrintWriter output;
- void setup() {
- size(800,600);
- PFont font;
- font = loadFont("Helvetica-48.vlw");
- textFont(font, 48);
- fill(#000000);
- output = createWriter("data/sourcefile.txt");
- }
- void draw(){
- background(#ffffff);
- smooth();
- htmlList = new HtmlList("http://syobonaction.tumblr.com/rss");
- ArrayList lines2 = (ArrayList) htmlList.getElements("title");
- output.println(lines2);
- output.flush(); // Writes the remaining data to the file
- output.close(); // Finishes the file
- delay(2500);
- println(lines2);
- }
1