6 Replies - 34477 Views - Last Post: 25 October 2015 - 11:34 AM

#1 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon

Reputation: 12634
  • View blog
  • Posts: 45,800
  • Joined: 27-December 08

Week #37- XML

Post icon  Posted 08 November 2010 - 10:23 AM

This week's challenge is XML.

XML is a markup language for encoding data in machine (and human) readable format. It is designed for simplicity and portability. XML tags are written using angle brackets <>, with the tag name and attributes inside in the format <tag attribute="value">.

Some Ideas for Challenges:
-Define your own XML format. This can be done using a number of schemas, including a Document Type Definition (DTD) or an XML Schema.
-Experiment with some XML parsing APIs including SAX, DOM, and a pull parser. Possibly work with the DIC API.
-Layout XML using CSS or XSLT
-Write a program to generate XML from existing data, perhaps including a SQL result set

-W3C XML Documentation
-KYA's Blog Entries on Parsing XML in Java and C#
-DIC API Feedback and Support forum

My Entry: My Write Columns of Table To XML snippet.
   @param $result: the result set from the SQL query
   @param $cols: the array of column names
   @param $filename: the name of the File to create
   @param $tagName: The name of the container tag for each row
   <pre>The File is assumed to not exist</pre>
public function queryToXML($result, array $cols, $filename, $tagName){
    $file = fopen($filename, "w"); //open up file stream

    //write initial XML heading
    fwrite($file, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
    //foreach row
    while($row = mysql_fetch_array($result)){
        fwrite($file, "<".$tagName.">\n");
        //write data using col name as tag
        foreach($cols as $tag){
        }//end foreach
        //close row tag
    }//end while

}//end queryToXML()

Is This A Good Question/Topic? 0
  • +

Replies To: Week #37- XML

#2 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: Week #37- XML

Posted 08 November 2010 - 10:50 AM

Since the vb.net 2008 release vb.net has made working with xml a lot simpler, with it inclusion of XML Literals.

So you can embed and work with xml directly in your code.

Also remember the web pages can be created with xml, if you follow the xhtml specification.
Was This Post Helpful? 3
  • +
  • -

#3 Munawwar   User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 457
  • Joined: 20-January 10

Re: Week #37- XML

Posted 08 November 2010 - 12:04 PM

I wrote a PHP script that sorts the D.I.C C++ tutorials (using D.I.C's XML "API") based on keywords stored in an XML file - Yea, I was bored :P. The code is too long to be posted here and is quite slow in execution as it downloads 7-8 XML files.
But for a demo check this.

This post has been edited by Munawwar: 08 November 2010 - 12:04 PM

Was This Post Helpful? 2
  • +
  • -

#4 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: Week #37- XML

Posted 08 November 2010 - 12:42 PM

Here's something I made using C# 4, the XDocument class and Linq. It's pretty neat and readable so anyone who wants to learn how to parse XML in a nice legible way should check it out! Better yet, help me finish it. :P

"SharpDIC is a library application made with C# that you can use to integrate any .NET application with DreamInCode using the official API. It provides common functionality right out of the box. It's free to use and anyone can contribute."

Was This Post Helpful? 1
  • +
  • -

#5 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2972
  • View blog
  • Posts: 11,223
  • Joined: 15-July 08

Re: Week #37- XML

Posted 08 November 2010 - 02:57 PM

Does it count if I already got 2nd in the API Contest?

Anyway, here is the biggest XML project I've ever done. It reads the XML backbone of DIC, fixes some invalid XML, then parse it, then read it and turn it into Java Code Data (like C++ structs). Finally, I take those classes and put them on a GUI to be read by all you guys. I need to find a way to optimize the process, as it takes several seconds for large topics.

Was This Post Helpful? 1
  • +
  • -

#6 mocker   User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 466
  • Joined: 14-October 07

Re: Week #37- XML

Posted 14 November 2010 - 09:52 AM

Been a while since I've been here and figured I should do a few of these.

I posted a Javascript function I use to parse Google Buzz XML and load an HTML div with a list of recent posts. I use it as a sidebar news feed on my website
Blog post with code

*/25 * * * * wget http://buzz.googleapis.com/feeds/(Google Username)/public/posted -O /home/(username)/Site/root/static/misc/buzz.xml


function loadBuzz(){
	var browser = navigator.appName ;
	var xhttp = ajaxRequest();
	xhttp.onerror = parseBuzzFail ;
	buzzDoc = xhttp.responseXML;
	if(xhttp.status == 200) { parseBuzz(); }
	else { 
		alert("Jiminy no doc- status: "+xhttp.status+" \ncontentType: "+xhttp.statusText);

function parseBuzz(){
	if(!buzzDoc) return;
	if(isIE && buzzDoc.readystate != 4) return;
	var entries = buzzDoc.getElementsByTagName("entry") ;
	var html = "<ul><li><b>Latest Buzz:</b></li>\n";
	for(var i=0; i<entries.length;i++)
		html =html + "<li>";
		if( entries[i].getElementsByTagName("updated").length > 0) html += "<span class='buzzbox'><i>"+entries[i].getElementsByTagName("updated")[0].childNodes[0].nodeValue+"</i></span><br>";
		if( entries[i].getElementsByTagName("link").length > 0) html += "<a href='"+entries[i].getElementsByTagName("link")[0].getAttribute("href")+"'>";
		else html += "<a target='#'>";
		html =html + entries[i].getElementsByTagName("summary")[0].childNodes[0].nodeValue+"</a></li><li></li>\n";
	html += "</ul>";

Was This Post Helpful? 3
  • +
  • -

#7 November-06   User is offline

  • D.I.C Regular

Reputation: 53
  • View blog
  • Posts: 482
  • Joined: 04-January 11

Re: Week #37- XML

Posted 25 October 2015 - 11:34 AM

I am currently learning XML with XSLT. Also, I am starting to learn Perl. My goal is to understand how to develop for/with XML Professional Publisher (XPP). I don't have an idea how XPP works except for my knowledge that it uses XML, XSLT, and Perl.

I can't find that much resources in the internet on this. If anyone has a knowledge of XPP, I would appreciate any help. Thanks.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1