Parsing XML files easily

To parse a XML (or KML or PMML) file easily without using any complicated softwares, here is a piece of code that fits right in your excel sheet.

Just import this file using Excel, and then use the function getElement, after pasting the XML code in 1 cell.

It is used  for simply reading the xml/kml code as a text string. Just pasted all the xml code in one cell, and used the start ,end function (for example start=<constraints> and end=</constraints> to get the value of constraints in the xml code).

Simply read into the value in another cell using the getElement function.

heres the code if you ever need it.Just paste it into the VB editor of Excel to create the GetElement function (if not there already) or simply import the file in the link above.

Attribute VB_Name = “Module1”
Public Function getElement(xml As String, start As String, finish As String)
For i = 1 To Len(xml)
If Mid(xml, i, Len(start)) = start Then
For j = i + Len(start) To Len(xml)
If Mid(xml, j, Len(finish)) = finish Then
getElement = Mid(xml, i + Len(start), j – i – Len(start))
Exit Function
End If
Next j
End If
Next i
End Function

FOR Using the R Package for parsing XML …………………………reference this site –

http://www.omegahat.org/RSXML/Overview.html

or this thread from R -Help

> Lines <- ‘
+ <root>
+  <data loc=”1″>
+    <val i=”t1″> 22 </val>
+    <val i=”t2″> 45 </val>
+  </data>
+  <data loc=”2″>
+    <val i=”t1″> 44 </val>
+    <val i=”t2″> 11 </val>
+  </data>
+ </root>
+ ‘
>
> library(XML)
> doc <- xmlTreeParse(Lines, asText = TRUE, trim = TRUE, useInternalNodes = TRUE)
> root <- xmlRoot(doc)
>
> data1 <- getNodeSet(root, “//data”)[[1]]
> xmlValue(getNodeSet(data1, “//val”)[[1]])
[1] ” 22 “

Google :Protocol Buffers and Lively

1) An Alternative to XML. This is quite a cool initiative as long as it doesnot lead to more skirmishes with the guys from redmond.http://code.google.com/apis/protocolbuffers/docs/overview.html

“”For example, let’s say you want to model a person with a name and an email. In XML, you need to do:
John Doe
jdoe@example.com

while the corresponding protocol buffer message definition (in protocol buffer text format) is:

# Textual representation of a protocol buffer.
# This is *not* the binary format used on the wire.
person {
name: “John Doe”
email: “jdoe@example.com”
}

In binary format, this message would probably be 28 bytes long and take around 100-200 nanoseconds to parse. The XML version is at least 69 bytes (if you remove whitespace) and would take around 5,000-10,000 nanoseconds to parse.

Also, manipulating a protocol buffer is much easier:

cout << “Name: ” << person.name() << endl;
cout << “E-mail: ” << person.email() << endl;

Whereas with XML you would have to do something like:

cout << “Name: ”
<< person.getElementsByTagName(“name”)->item(0)->innerText()
<< endl;
cout << “E-mail: ”
<< person.getElementsByTagName(“email”)->item(0)->innerText()
<< endl;

However, protocol buffers are not always a better solution than XML – for instance, protocol buffers would not be a good way to model a text-based document with markup (e.g. HTML), since you cannot easily interleave structure with text. In addition, XML is human-readable and human-editable; protocol buffers, at least in their native format, are not. XML is also – to some extent – self-describing. A protocol buffer is only meaningful if you have the message definition (the .proto file).””

We think it is one more Google googly at Microsoft (!). But if its faster for consumers so be it.

2) www.lively.com

This one is like Yahoo Avatars or a crude Second Life. We downloaded  it, the app was quite small, but running it was slow ,and  bandwidth heavy (I tested Eve online on the same bandwidth)As more developers pile on, it should get bigger inevitably. Its a fun project but yes you can prompted to click remember chat history ( so as Google can tie up more behavioral ad- targeting to your IP address). Ouch !