Skip to content
Permalink
Browse files

various fixes

  • Loading branch information...
DXSdata committed Sep 4, 2019
1 parent 0f429bd commit 68b45c52bbaea89ac435109fd21776e03801df29
Showing with 39 additions and 4 deletions.
  1. +1 −0 openTRANS/Order.cs
  2. +37 −3 openTRANS/XmlCreator.cs
  3. +1 −1 openTRANS/openTRANS.csproj
@@ -179,6 +179,7 @@ public class OrderItem
public ProductId ProductId = new ProductId();

[XmlArray("PRODUCT_FEATURES")]
[XmlArrayItem("FEATURE")]
public List<Feature> ProductFeatures = new List<Feature>();

[XmlElement("QUANTITY")]
@@ -10,7 +10,7 @@ namespace openTRANS
public class XmlCreator
{
private string xmlVersion = "1.0";
private Encoding encoding = Encoding.UTF8; //In case of changing also change StringWriter below; would otherwise produce wrong xml encoding attribute
private Encoding encoding = new UpperCaseUTF8Encoding(); //Previously Encoding.Utf8; in case of changing also change StringWriter below; would otherwise produce wrong xml encoding attribute
private bool standalone = true;

//private XNamespace xmlns = "http://www.opentrans.org/XMLSchema/2.1";
@@ -39,7 +39,7 @@ public string Result
get
{
var xdoc = new XDocument(
new XDeclaration(xmlVersion, encoding.WebName.ToUpper(), standalone ? "yes" : "no")
new XDeclaration(xmlVersion, encoding.WebName, standalone ? "yes" : "no")
);


@@ -51,7 +51,7 @@ public string Result


XmlSerializer serializer = new XmlSerializer(typeof(Order));
using (var writer = new Utf8StringWriter())
using (var writer = new UTF8StringWriter())
{
serializer.Serialize(writer, order, xmlns);
return writer.ToString();
@@ -64,5 +64,39 @@ private class Utf8StringWriter : StringWriter
{
public override Encoding Encoding { get { return Encoding.UTF8; } }
}

//writes UTF-8 in uppercase; see class below
private class UTF8StringWriter : StringWriter
{
public override Encoding Encoding { get { return new UpperCaseUTF8Encoding(); } }
}


/// <summary>
/// Sometimes utf-8 definition in first line needed in uppercase by suppliers.
/// https://stackoverflow.com/questions/4291332/utf-8-in-uppercase
/// </summary>
public class UpperCaseUTF8Encoding : UTF8Encoding
{

public override string WebName
{
get { return base.WebName.ToUpper(); }
}

public static UpperCaseUTF8Encoding UpperCaseUTF8
{
get
{
if (upperCaseUtf8Encoding == null)
{
upperCaseUtf8Encoding = new UpperCaseUTF8Encoding();
}
return upperCaseUtf8Encoding;
}
}

private static UpperCaseUTF8Encoding upperCaseUtf8Encoding = null;
}
}
}
@@ -6,7 +6,7 @@
<Authors>DXSdata</Authors>
<Company>DXSdata GmbH</Company>
<Description>.NET Core / Standard implementation of the openTRANS v2.1 definitions by Fraunhofer IAO</Description>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
</PropertyGroup>

</Project>

0 comments on commit 68b45c5

Please sign in to comment.
You can’t perform that action at this time.