diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e92b220
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,263 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+
+# Visual Studio 2015 cache/options directory
+.vs/
+.nuget/
+.git/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUNIT
+*.VisualState.xml
+TestResult.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# DNX
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+*_i.c
+*_p.c
+*_i.h
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# JustCode is a .NET coding add-in
+.JustCode
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# TODO: Comment the next line if you want to checkin your web deploy settings
+# but database connection strings (with potential passwords) will be unencrypted
+#*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# The packages folder can be ignored because of Package Restore
+**/packages/*
+# except build/, which is used as an MSBuild target.
+!**/packages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/packages/repositories.config
+# NuGet v3's project.json files produces more ignoreable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+node_modules/
+orleans.codegen.cs
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+*.mdf
+*.ldf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# JetBrains Rider
+.idea/
+*.sln.iml
+
+# CodeRush
+.cr/
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
\ No newline at end of file
diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config
deleted file mode 100644
index 6a318ad..0000000
--- a/.nuget/NuGet.Config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.nuget/NuGet.exe b/.nuget/NuGet.exe
deleted file mode 100644
index ddc9105..0000000
Binary files a/.nuget/NuGet.exe and /dev/null differ
diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets
deleted file mode 100644
index b44341f..0000000
--- a/.nuget/NuGet.targets
+++ /dev/null
@@ -1,150 +0,0 @@
-
-
-
- $(MSBuildProjectDirectory)\..\
-
-
- false
-
-
- false
-
-
- true
-
-
- false
-
-
-
-
-
-
-
-
-
- $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
- $([System.IO.Path]::Combine($(ProjectDir), "packages.config"))
-
-
-
-
- $(SolutionDir).nuget
- packages.config
-
-
-
-
- $(NuGetToolsPath)\nuget.exe
- @(PackageSource)
-
- "$(NuGetExePath)"
- mono --runtime=v4.0.30319 $(NuGetExePath)
-
- $(TargetDir.Trim('\\'))
-
- -RequireConsent
-
- $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "
- $(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols
-
-
-
- RestorePackages;
- $(ResolveReferencesDependsOn);
-
-
-
-
- $(BuildDependsOn);
- BuildPackage;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index a005f3b..7d2d164 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,20 @@
# XML2JSON
-XML2JSON is a simple command line tool for converting XML files to JSON. It uses the JSON.NET library.
+XML2JSON: convert XML files to JSON using an XDS file to make a list of single XML elements into a JSON array where necessary.
+
+It uses the JSON.NET library.
## Usage:
- XML2JSON.exe input.xml output.json
+ XML2JSON.exe input.xml input.xsd output.json
+
+## Example input.xds:
+Assuming that input.xds has a complex element types of genre and book, with maxOccues > 1, that will give as a list of elements of:
+
+ genre
+ book
-## Example Input:
+## Example XML Input:
@@ -19,42 +27,32 @@ XML2JSON is a simple command line tool for converting XML files to JSON. It uses
An in-depth look at creating applications
with XML.
-
- Ralls, Kim
- Midnight Rain
- Fantasy
- 5.95
- 2000-12-16
- A former architect battles corporate zombies,
- an evil sorceress, and her own childhood to become queen
- of the world.
-
## Example Output:
- {
- "catalog": {
- "book": [
- {
- "id": "bk101",
- "author": "Gambardella, Matthew",
- "title": "XML Developer's Guide",
- "genre": "Computer",
- "price": "44.95",
- "publish_date": "2000-10-01",
- "description": "An in-depth look at creating applications \r\n with XML."
- },
- {
- "id": "bk102",
- "author": "Ralls, Kim",
- "title": "Midnight Rain",
- "genre": "Fantasy",
- "price": "5.95",
- "publish_date": "2000-12-16",
- "description": "A former architect battles corporate zombies, \r\n an evil sorceress, and her own childhood to become queen \r\n of the world."
- }
- ]
- }
- }
-
\ No newline at end of file
+ {
+ "catalog": {
+ "book": [
+ {
+ "id": "bk101",
+ "author": "Gambardella, Matthew",
+ "title": "XML Developer's Guide",
+ "genre": [
+ {
+ "id": 1,
+ "text": "Computer"
+ }
+ ],
+ "price": 44.95,
+ "publish_date": "2000-10-01",
+ "description": "An in-depth look at creating applications \r\n with XML."
+ }
+ ]
+ }
+ }
+
+## Note
+
+So, while there is just one "book" element and one "genre" element, because they are included in the elements list, they are
+made into JSON arrays. This is helpful because Newtonsoft cannot use either XSD or JSON Schema files.
\ No newline at end of file
diff --git a/SampleData/book.xml b/SampleData/book.xml
new file mode 100644
index 0000000..8b35c3b
--- /dev/null
+++ b/SampleData/book.xml
@@ -0,0 +1,12 @@
+
+
+
+ Gambardella, Matthew
+ XML Developer's Guide
+ Computer
+ 44.95
+ 2000-10-01
+ An in-depth look at creating applications
+ with XML.
+
+
\ No newline at end of file
diff --git a/SampleData/elements.txt b/SampleData/elements.txt
new file mode 100644
index 0000000..a18e7db
--- /dev/null
+++ b/SampleData/elements.txt
@@ -0,0 +1,2 @@
+genre
+book
\ No newline at end of file
diff --git a/SampleData/schema.xsd b/SampleData/schema.xsd
new file mode 100644
index 0000000..11d61c4
--- /dev/null
+++ b/SampleData/schema.xsd
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SampleData/xml.xml b/SampleData/xml.xml
new file mode 100644
index 0000000..d0c5ecf
--- /dev/null
+++ b/SampleData/xml.xml
@@ -0,0 +1,25 @@
+
+
+
+ BMW
+ 2008-10-25
+ 2002-05-30T09:30:10Z
+
+ black
+
+ This is the text
+
+
+ BMW UK
+ 2.1
+
+
+ Honda
+
+ red
+ 16711680
+
+ UK Manufacturing Ltd
+ 1.0
+
+
\ No newline at end of file
diff --git a/XML2JSON.Azure/ServiceConfiguration.Cloud.cscfg b/XML2JSON.Azure/ServiceConfiguration.Cloud.cscfg
deleted file mode 100644
index cbcd581..0000000
--- a/XML2JSON.Azure/ServiceConfiguration.Cloud.cscfg
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/XML2JSON.Azure/ServiceConfiguration.Local.cscfg b/XML2JSON.Azure/ServiceConfiguration.Local.cscfg
deleted file mode 100644
index cbcd581..0000000
--- a/XML2JSON.Azure/ServiceConfiguration.Local.cscfg
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/XML2JSON.Azure/ServiceDefinition.csdef b/XML2JSON.Azure/ServiceDefinition.csdef
deleted file mode 100644
index 29aa10e..0000000
--- a/XML2JSON.Azure/ServiceDefinition.csdef
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/XML2JSON.Azure/XML2JSON.Azure.ccproj b/XML2JSON.Azure/XML2JSON.Azure.ccproj
deleted file mode 100644
index 5c1866d..0000000
--- a/XML2JSON.Azure/XML2JSON.Azure.ccproj
+++ /dev/null
@@ -1,63 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- 2.3
- 7974c5ee-ec21-4dc8-9494-e55f6e4cf504
- Library
- Properties
- XML2JSON.Azure
- XML2JSON.Azure
- True
- XML2JSON.Azure
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
- XML2JSON.Web.OWIN
- {a4316291-bed8-4315-be70-7d8046ab4a5c}
- True
- Web
- XML2JSON.Web.OWIN
- True
-
-
-
-
-
-
-
- Content
-
-
-
-
- 10.0
- $(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\2.3\
-
-
-
\ No newline at end of file
diff --git a/XML2JSON.Azure/XML2JSON.Web.OWINContent/diagnostics.wadcfg b/XML2JSON.Azure/XML2JSON.Web.OWINContent/diagnostics.wadcfg
deleted file mode 100644
index 42d555b..0000000
--- a/XML2JSON.Azure/XML2JSON.Web.OWINContent/diagnostics.wadcfg
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/XML2JSON.Core/Converter.cs b/XML2JSON.Core/Converter.cs
index 5bdbbb5..25361d7 100644
--- a/XML2JSON.Core/Converter.cs
+++ b/XML2JSON.Core/Converter.cs
@@ -1,8 +1,10 @@
-using System.Linq;
+using System.Collections.Generic;
+using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
using Formatting = Newtonsoft.Json.Formatting;
namespace XML2JSON.Core
@@ -10,14 +12,25 @@ namespace XML2JSON.Core
///
/// Class to handle xml -> json conversion
///
- public static class Converter
+ public class Converter
{
+
+ ///
+ /// async version of conversion function
+ ///
+ ///
+ ///
+ public async Task ConvertToJsonAsync(string xml, List elementsToMakeArrays)
+ {
+ return await Task.Factory.StartNew(() => ConvertToJson(xml, elementsToMakeArrays));
+ }
+
///
/// converts xml string to json string
///
/// xml data as string
/// json data as string
- public static string ConvertToJson(string xml)
+ public string ConvertToJson(string xml, ICollection elements)
{
var doc = new XmlDocument();
doc.LoadXml(xml);
@@ -43,18 +56,78 @@ public static string ConvertToJson(string xml)
// unquote numbers and booleans
strippedJsonText = Regex.Replace(strippedJsonText, "\\\"([\\d\\.]+)\\\"", "$1", RegexOptions.IgnoreCase);
strippedJsonText = Regex.Replace(strippedJsonText, "\\\"(true|false)\\\"", "$1", RegexOptions.IgnoreCase);
-
+
+ strippedJsonText = FixArrayElements(elements, strippedJsonText);
+
return strippedJsonText;
}
- ///
- /// async version of conversion function
- ///
- ///
- ///
- public static async Task ConvertToJsonAsync(string xml)
+ private JToken MakeElementArray(JToken jToken)
+ {
+ List