Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 47cd4c72 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

avoid illegal characters in id attribute

parent 3720be35
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,7 @@ using System; ...@@ -33,6 +33,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using System.Xml; using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using TUGraz.IVT.VectoXML; using TUGraz.IVT.VectoXML;
...@@ -120,8 +121,11 @@ namespace TUGraz.VectoCore.OutputData.XML ...@@ -120,8 +121,11 @@ namespace TUGraz.VectoCore.OutputData.XML
var vehicle = data.VehicleInputData; var vehicle = data.VehicleInputData;
var angledrive = data.AngledriveInputData; var angledrive = data.AngledriveInputData;
var id = CreateIdString("VEH-" + vehicle.Model);
return new XElement(tns + XMLNames.Component_Vehicle, return new XElement(tns + XMLNames.Component_Vehicle,
new XAttribute(XMLNames.Component_ID_Attr, "VEH-" + vehicle.Model), new XAttribute(XMLNames.Component_ID_Attr, id),
GetDefaultComponentElements(vehicle.CertificationNumber, vehicle.Model, "N.A."), GetDefaultComponentElements(vehicle.CertificationNumber, vehicle.Model, "N.A."),
new XElement(tns + XMLNames.Vehicle_LegislativeClass, "N3"), new XElement(tns + XMLNames.Vehicle_LegislativeClass, "N3"),
new XElement(tns + XMLNames.Vehicle_VehicleCategory, vehicle.VehicleCategory.ToXMLFormat()), new XElement(tns + XMLNames.Vehicle_VehicleCategory, vehicle.VehicleCategory.ToXMLFormat()),
...@@ -156,7 +160,8 @@ namespace TUGraz.VectoCore.OutputData.XML ...@@ -156,7 +160,8 @@ namespace TUGraz.VectoCore.OutputData.XML
protected XElement CreateEngine(IEngineDeclarationInputData data, XNamespace ns = null) protected XElement CreateEngine(IEngineDeclarationInputData data, XNamespace ns = null)
{ {
var id = string.Format("ENG-{0}", data.Model.RemoveWhitespace()); var id = CreateIdString(string.Format("ENG-{0}", data.Model.RemoveWhitespace()));
var fld = FullLoadCurveReader.Create(data.FullLoadCurve, true); var fld = FullLoadCurveReader.Create(data.FullLoadCurve, true);
return new XElement((ns ?? tns) + XMLNames.Component_Engine, return new XElement((ns ?? tns) + XMLNames.Component_Engine,
new XElement(tns + XMLNames.ComponentDataWrapper, new XElement(tns + XMLNames.ComponentDataWrapper,
...@@ -204,7 +209,9 @@ namespace TUGraz.VectoCore.OutputData.XML ...@@ -204,7 +209,9 @@ namespace TUGraz.VectoCore.OutputData.XML
); );
gears.Add(gear); gears.Add(gear);
} }
var id = string.Format("GBX-{0}", gbxData.Model.RemoveWhitespace()); var id = CreateIdString(string.Format("GBX-{0}", gbxData.Model.RemoveWhitespace()));
return new XElement((ns ?? tns) + XMLNames.Component_Gearbox, return new XElement((ns ?? tns) + XMLNames.Component_Gearbox,
new XElement(tns + XMLNames.ComponentDataWrapper, new XElement(tns + XMLNames.ComponentDataWrapper,
new XAttribute(XMLNames.Component_ID_Attr, id), new XAttribute(XMLNames.Component_ID_Attr, id),
...@@ -223,7 +230,10 @@ namespace TUGraz.VectoCore.OutputData.XML ...@@ -223,7 +230,10 @@ namespace TUGraz.VectoCore.OutputData.XML
if (data == null) { if (data == null) {
throw new Exception("Torque Converter is required!"); throw new Exception("Torque Converter is required!");
} }
var id = string.Format("TC-{0}", data.Model.RemoveWhitespace());
var id = CreateIdString(string.Format("TC-{0}", data.Model.RemoveWhitespace()));
return new XElement(tns + XMLNames.Component_TorqueConverter, return new XElement(tns + XMLNames.Component_TorqueConverter,
new XElement(tns + XMLNames.ComponentDataWrapper, new XElement(tns + XMLNames.ComponentDataWrapper,
new XAttribute(XMLNames.Component_ID_Attr, id), new XAttribute(XMLNames.Component_ID_Attr, id),
...@@ -241,7 +251,8 @@ namespace TUGraz.VectoCore.OutputData.XML ...@@ -241,7 +251,8 @@ namespace TUGraz.VectoCore.OutputData.XML
private XElement CreateAngleDrive(IAngledriveInputData data, XNamespace ns = null) private XElement CreateAngleDrive(IAngledriveInputData data, XNamespace ns = null)
{ {
var id = string.Format("ANGL-{0}", data.Model.RemoveWhitespace()); var id = CreateIdString(string.Format("ANGL-{0}", data.Model.RemoveWhitespace()));
return new XElement((ns ?? tns) + XMLNames.Component_Angledrive, return new XElement((ns ?? tns) + XMLNames.Component_Angledrive,
new XElement(tns + XMLNames.ComponentDataWrapper, new XElement(tns + XMLNames.ComponentDataWrapper,
new XAttribute(XMLNames.Component_ID_Attr, id), new XAttribute(XMLNames.Component_ID_Attr, id),
...@@ -255,7 +266,8 @@ namespace TUGraz.VectoCore.OutputData.XML ...@@ -255,7 +266,8 @@ namespace TUGraz.VectoCore.OutputData.XML
public XElement CreateRetarder(IRetarderInputData data, XNamespace ns = null) public XElement CreateRetarder(IRetarderInputData data, XNamespace ns = null)
{ {
var id = string.Format("RET-{0}", data.Model.RemoveWhitespace()); var id = CreateIdString(string.Format("RET-{0}", data.Model.RemoveWhitespace()));
return new XElement((ns ?? tns) + XMLNames.Component_Retarder, return new XElement((ns ?? tns) + XMLNames.Component_Retarder,
new XElement(tns + XMLNames.ComponentDataWrapper, new XElement(tns + XMLNames.ComponentDataWrapper,
new XAttribute(XMLNames.Component_ID_Attr, id), new XAttribute(XMLNames.Component_ID_Attr, id),
...@@ -271,7 +283,8 @@ namespace TUGraz.VectoCore.OutputData.XML ...@@ -271,7 +283,8 @@ namespace TUGraz.VectoCore.OutputData.XML
public XElement CreateAxlegear(IAxleGearInputData data, XNamespace ns = null) public XElement CreateAxlegear(IAxleGearInputData data, XNamespace ns = null)
{ {
var typeId = string.Format("AXLGEAR-{0}", data.Ratio.ToString("F3", CultureInfo.InvariantCulture)); var typeId = CreateIdString(string.Format("AXLGEAR-{0}", data.Ratio.ToString("F3", CultureInfo.InvariantCulture)));
return new XElement((ns ?? tns) + XMLNames.Component_Axlegear, return new XElement((ns ?? tns) + XMLNames.Component_Axlegear,
new XElement(tns + XMLNames.ComponentDataWrapper, new XElement(tns + XMLNames.ComponentDataWrapper,
new XAttribute(XMLNames.Component_ID_Attr, typeId), new XAttribute(XMLNames.Component_ID_Attr, typeId),
...@@ -310,7 +323,8 @@ namespace TUGraz.VectoCore.OutputData.XML ...@@ -310,7 +323,8 @@ namespace TUGraz.VectoCore.OutputData.XML
private XElement CreateTyre(IAxleDeclarationInputData axle) private XElement CreateTyre(IAxleDeclarationInputData axle)
{ {
var id = string.Format("TYRE-{0}", axle.Wheels).RemoveWhitespace().Replace("/", "_"); var id = CreateIdString(string.Format("TYRE-{0}", axle.Wheels).Replace("/", "_"));
return new XElement(tns + "Tyre", return new XElement(tns + "Tyre",
new XElement(tns + XMLNames.ComponentDataWrapper, new XElement(tns + XMLNames.ComponentDataWrapper,
new XAttribute(XMLNames.Component_ID_Attr, id), new XAttribute(XMLNames.Component_ID_Attr, id),
...@@ -344,7 +358,8 @@ namespace TUGraz.VectoCore.OutputData.XML ...@@ -344,7 +358,8 @@ namespace TUGraz.VectoCore.OutputData.XML
private XElement CreateAirdrag(IAirdragDeclarationInputData data, XNamespace ns = null) private XElement CreateAirdrag(IAirdragDeclarationInputData data, XNamespace ns = null)
{ {
var id = string.Format("Airdrag-{0}", data.Model); var id = CreateIdString(string.Format("Airdrag-{0}", data.Model));
return new XElement((ns ?? tns) + XMLNames.Component_AirDrag, return new XElement((ns ?? tns) + XMLNames.Component_AirDrag,
new XElement(tns + XMLNames.ComponentDataWrapper, new XElement(tns + XMLNames.ComponentDataWrapper,
new XAttribute(XMLNames.Component_ID_Attr, id), new XAttribute(XMLNames.Component_ID_Attr, id),
...@@ -401,5 +416,11 @@ namespace TUGraz.VectoCore.OutputData.XML ...@@ -401,5 +416,11 @@ namespace TUGraz.VectoCore.OutputData.XML
new XElement(tns + XMLNames.Component_Date, XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Utc)), new XElement(tns + XMLNames.Component_Date, XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Utc)),
}; };
} }
private string CreateIdString(string id)
{
var regexp = new Regex("[^a-zA-Z0-9_-]");
return regexp.Replace(id, "");
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment