public virtual string Format(IXmlFormat format, string xml)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            var root          = this.Parser.Parse(xml);
            var xmlDelaration = this.GetXmlDeclaration(root);
            var encoding      = this.GetEncoding(xmlDelaration);

            var attributeComparer = this.AttributeComparerFactory.Create(format.AttributeFormat);

            this.SortAttributesRecursive(attributeComparer, root);

            var elementComparer = this.ElementComparerFactory.Create(format.ElementFormat);

            this.SortElementsRecursive(elementComparer, root);

            string formattedXml;

            using (var stream = new MemoryStream())
            {
                using (var xmlWriter = XmlWriter.Create(stream, this.CreateXmlWriterSettings(encoding, format, xmlDelaration == null)))
                {
                    xmlWriter.WriteNode(root.CreateNavigator(), true);
                }

                var bytes = stream.ToArray().Skip(encoding.GetPreamble().Length).ToArray();
                formattedXml = encoding.GetString(bytes);
            }

            return(formattedXml);
        }
 public WxmjCommandFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
Ejemplo n.º 3
0
 public JingXieFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
Ejemplo n.º 4
0
 public MenJinShouQuanFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
Ejemplo n.º 5
0
 public LvYeFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
 public DuanXinFaSongFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
 public MenJinErQiFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
Ejemplo n.º 8
0
 public HouseAndUserCardFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
Ejemplo n.º 9
0
 public QiangZhiGuanKongFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
 public WxmjAuthorizeCommandFactory(IXmlFormat xmlFormat)
 {
     // TODO: Complete member initialization
     this.xmlFormat = xmlFormat;
 }
        protected internal virtual XmlWriterSettings CreateXmlWriterSettings(Encoding encoding, IXmlFormat format, bool omitXmlDeclaration)
        {
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            return(new XmlWriterSettings
            {
                Encoding = encoding,
                Indent = format.Indent,
                IndentChars = format.IndentString,
                NewLineChars = format.NewLineString,
                OmitXmlDeclaration = omitXmlDeclaration
            });
        }
 public QykqCommandFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
 public QiYeFangHuFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
 public ChuZuWuAnFangFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
Ejemplo n.º 15
0
 public SocialAppTerminalFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
Ejemplo n.º 16
0
 public YiKaGuanChuanFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
 public AgreementFormatFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }
 public DengJiJiFactory(IXmlFormat xmlFormat)
 {
     this.xmlFormat = xmlFormat;
 }