|
JSOM BackgroundJSOM is an alternative to E4X for accessing the XML content. E4X has been here for a long time. However, IE6 and IE7 are still the most popular browsers. It is very unlikely that E4X is going to be get popular for the development. XML parsing is quite a burden in JavaScript. That's why JSON is popular in recent development of AJAX application. Instead of parsing the XML again and again for different document types, we can parse the XML in JavaScript Object Model (JSOM), just like E4X. In fact, JSOM should be similar to how E4X access XML. The only difference is @ is not a valid character for a JavaScript identifier. $ is used to replace @ as a workaround. Usagexml='<invoice date="01-20-2000" number="123">' + ' <address country="US">' + ' <name>John Smith</name>' + ' <street>123 George St.</street>' + ' <city>Mountain View</city>' + ' <state>CA</state>' + ' <zip>94041</zip>' + ' </address>' + '</invoice>'; invoice = JSOM(xml); alert(invoice.$number); alert(invoice.address.name); ConfigurationIf you do not like using $ as the attribute prefix, you can change like this: JSOM.attributePrefix = ""; invoice = JSOM(xml); alert(invoice.number); alert(invoice.address.name); Download[ Download JSOM ] Example
AcknowledgementThis project is inspired by IEE4X |