示例#1
0
        public static Json.Index LibraryToIndex(Xml.Library library)
        {
            Json.Index index = new Json.Index(library.version, library.language);

            // Capture references from library
            foreach (Xml.StudyResource resource in library.resources)
            {
                Xml.ScriptureReference oldReference = Xml.ScriptureReference.Parse(resource.reference);

                // Format book for enum parsing
                string bookString = oldReference.book;

                // For book numbers
                if (bookString[1] == ' ')
                {
                    bookString += bookString[0];
                    bookString  = bookString.Substring(2);
                }

                // For whitespace
                bookString = bookString.Replace(" ", "");

                // Create new reference
                Json.Volume    volume    = (Json.Volume)resource.category;
                Json.Book      book      = (Json.Book)Enum.Parse(typeof(Json.Book), bookString, true);
                Json.Reference reference = new Json.Reference(volume, book, oldReference.chapter, oldReference.verses);

                // Add reference to topic collection for all topics
                foreach (string topicName in resource.topics)
                {
                    Json.Topic topic = index.ByName(topicName);

                    if (topic == null)
                    {
                        topic = new Json.Topic(topicName.ToLower().Replace(' ', '_'), topicName);
                        index.topics.Add(topic);
                    }

                    topic.references.Add(reference);
                }
            }

            return(index);
        }
示例#2
0
        static void Main(string[] args)
        {
            // Check arguments
            if (args.Length < 2)
            {
                throw new ArgumentException("Not enough arguments provided.");
            }

            if (!File.Exists(args[0]))
            {
                throw new FileNotFoundException("The given input file does not exist.");
            }

            // Read XML file
            StreamReader inputXml = new StreamReader(args[0]);

            XmlDocument doc = new XmlDocument();

            doc.Load(inputXml);
            Xml.Library library = new Xml.Library(doc.GetElementsByTagName("library")[0]);

            inputXml.Close();

            // Convert XML to JSON
            Json.Index index = Converter.LibraryToIndex(library);
            string     json  = index.ToJson();

            // Write JSON file
            StreamWriter outputJson = new StreamWriter(args[1], false);

            outputJson.Write(json);
            outputJson.Close();

            // Print human readable format
            Console.WriteLine(index.ToString());
        }