<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace AllfleXML.FlexOrder
{
    public static class Parser
    {
        public static Document Import(string xmlFilePath)
        {
            return Import(XDocument.Load(xmlFilePath));
        }

        public static Document Import(XDocument document)
        {
            var validation = Validate(document);
            if (!validation.Item1)
            {
                throw new XmlSchemaValidationException(validation.Item2);
            }

            Document result;

            var rootElement = document.Document?.Root?.Name.ToString();
            if (rootElement == "OrderHeader")
            {
                // TODO: Deprecate this.
                Trace.WriteLine("Document users OrderHeader as root node. This feature is obsolete, please wrap the OrderHeader node in a Document node.");
                result = new Document {OrderHeaders = new List<OrderHeader>()};
                var serializer = new XmlSerializer(typeof(OrderHeader));
                using (var reader = new StringReader(document.ToString()))
                {
                    result.OrderHeaders.Add((OrderHeader)serializer.Deserialize(reader));
                }
            }
            else
            {
                var serializer = new XmlSerializer(typeof(Document));
                using (var reader = new StringReader(document.ToString()))
                {
                    result = (Document)serializer.Deserialize(reader);
                }
            }

            return result;
        }

        public static XDocument Export(this OrderHeader order)
        {
            return Export(new Document { OrderHeaders = new List<OrderHeader> { order } });
        }

        public static XDocument Export(this Document document)
        {
            var result = new XDocument();
            using (var writer = result.CreateWriter())
            {
                var serializer = new XmlSerializer(document.GetType());
                serializer.Serialize(writer, document);
            }
            return result;
        }
<commit_msg>Export as just orderHeader for API spec<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace AllfleXML.FlexOrder
{
    /// <summary>
    /// 
    /// </summary>
    public static class Parser
    {
        public static Document Import(string xmlFilePath)
        {
            return Import(XDocument.Load(xmlFilePath));
        }

        public static Document Import(XDocument document)
        {
            var validation = Validate(document);
            if (!validation.Item1)
            {
                throw new XmlSchemaValidationException(validation.Item2);
            }

            Document result;

            var rootElement = document.Document?.Root?.Name.ToString();
            if (rootElement == "OrderHeader")
            {
                // TODO: Deprecate this.
                Trace.WriteLine("Document users OrderHeader as root node. This feature is obsolete, please wrap the OrderHeader node in a Document node.");
                result = new Document {OrderHeaders = new List<OrderHeader>()};
                var serializer = new XmlSerializer(typeof(OrderHeader));
                using (var reader = new StringReader(document.ToString()))
                {
                    result.OrderHeaders.Add((OrderHeader)serializer.Deserialize(reader));
                }
            }
            else
            {
                var serializer = new XmlSerializer(typeof(Document));
                using (var reader = new StringReader(document.ToString()))
                {
                    result = (Document)serializer.Deserialize(reader);
                }
            }

            return result;
        }

        public static XDocument Export(this OrderHeader order)
        {
            var result = new XDocument();
            using (var writer = result.CreateWriter())
            {
                var serializer = new XmlSerializer(order.GetType());
                var ns = new XmlSerializerNamespaces();
                ns.Add("", "");
                serializer.Serialize(writer, order, ns);
            }
            return result;
        }

        public static XDocument Export(this Document document)
        {
            var result = new XDocument();
            using (var writer = result.CreateWriter())
            {
                var serializer = new XmlSerializer(document.GetType());
                var ns = new XmlSerializerNamespaces();
                ns.Add("", "");
                serializer.Serialize(writer, document, ns);
            }
            return result;
        }

{'fraction_non_alphanumeric': 0.08752950432730133, 'fraction_numerical': 0.0007867820613690008, 'mean_word_length': 1.712, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2246826', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1140, 'n_words': 311}