.NET XMLBuilder, a .NET port of Java XMLBuilder
Yesteday I finished the port of Java XMLBuilder to .NET, now you can use any .NET language to easily create xml documents, .NET XMLBuilder is written in Delphi Prism and released under Apache 2.0 license. The current release of XMLBuilder can be download here.
XMLBuilder is very easy to use, it contains a kind of DSL, a basic example can be checked below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | XMLBuilder builder = XMLBuilder.Start("plist").A("version", "1.0"); builder.AddXmlDeclaration("1.0", "UTF-8", "yes"); builder.AddDocumentType("plist", "-//Apple Computer//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd"); XMLBuilder array = builder.E("dict") .E("key") .T("cities") .Up() .E("array"); XMLBuilder cityDict = array.E("dict"); cityDict.E("key") .T("title") .Up() .E("string") .T(utf8.GetString(ascii.GetBytes("São Paulo"))) .Up() .E("key") .T("latitude") .Up() .E("real") .T(Convert.ToString(44.898997)) .Up() .E("key") .T("longitude") .Up() .E("real") .T(Convert.ToString(23.8989989)) .Up(2); cityDict = array.E("dict"); cityDict.E("key") .T("title") .Up() .E("string") .T(utf8.GetString(ascii.GetBytes("Rio de Janeiro"))) .Up() .E("key") .T("latitude") .Up() .E("real") .T(Convert.ToString(44.898997)) .Up() .E("key") .T("longitude") .Up() .E("real") .T(Convert.ToString(23.8989989)) .Up(2); cityDict = array.E("dict"); cityDict.E("key") .T("title") .Up() .E("string") .T(utf8.GetString(ascii.GetBytes("Brasília"))) .Up() .E("key") .T("latitude") .Up() .E("real") .T(Convert.ToString(44.898997)) .Up() .E("key") .T("longitude") .Up() .E("real") .T(Convert.ToString(23.8989989)) .Up(2); builder.AsString(); |
Here’s the output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>cities</key> <array> <dict> <key>title</key> <string>Sao Paulo</string> <key>latitude</key> <real>44,898997</real> <key>longitude</key> <real>23,8989989</real> </dict> <dict> <key>title</key> <string>Rio de Janeiro</string> <key>latitude</key> <real>44,898997</real> <key>longitude</key> <real>23,8989989</real> </dict> <dict> <key>title</key> <string>Brasilia</string> <key>latitude</key> <real>44,898997</real> <key>longitude</key> <real>23,8989989</real> </dict> </array> </dict> </plist> |