Wednesday, February 27, 2013

AngularJs and Xml

Scenario: using an xml database, need to make a list of documents for user to select to edit.  This info is in the database as xml.

Problem: When converting xml to json on the server… single items are not arrays, more than one item is an array.  Array items need to be an array even if there is only one item. 

Solution: convert client side with https://code.google.com/p/x2js/ 

When x2js converts xml to Json, it provides both an array format or a single item format for elements that could be either. 

Oh! Namespace support!  That made my day!  It was even done in an elegant manner.  Namespaces stay out of the way till you get down to work on the text element!

I was expecting the JSON to be  f.rows.f.row.f.name

but no, it was so much better -  rows.row.name.__text

for the namespace – rows.row.name.__prefix

I found this on http://rabidgadfly.com/2013/02/ I’m glad he created this post a week before I needed it.

Mad style points for Glenn for use of http://plnkr.co and for the Guitar legends xml data set!

No comments:

Post a Comment