Skip to content

Commit

Permalink
Avoid property name clashes
Browse files Browse the repository at this point in the history
Use qualified form for global attributes
  • Loading branch information
Michael Ganss committed Jul 27, 2020
1 parent 90a9b7b commit 78e1034
Show file tree
Hide file tree
Showing 14 changed files with 753 additions and 5 deletions.
4 changes: 2 additions & 2 deletions XmlSchemaClassGenerator.Tests/NamespaceProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void TestParseNamespaceUtilityMethod1(string xmlNs, string xmlSchema, str
string customNsPattern = "{0}|{1}={2}";

var uri = new Uri(xmlSchema, UriKind.RelativeOrAbsolute);
var fullNetNs = (string.IsNullOrEmpty(netPrefix)) ? netNs : string.Join('.', netPrefix, netNs);
var fullNetNs = (string.IsNullOrEmpty(netPrefix)) ? netNs : string.Join(".", netPrefix, netNs);

var expected = new KeyValuePair<NamespaceKey, string>(new NamespaceKey(uri, xmlNs), fullNetNs);
var actual = CodeUtilities.ParseNamespace(string.Format(customNsPattern, xmlNs, xmlSchema, netNs), netPrefix);
Expand All @@ -95,7 +95,7 @@ public void TestParseNamespaceUtilityMethod2(string xmlSchema, string netNs, str
{
string customNsPattern = "{0}={1}";

var fullNetNs = (string.IsNullOrEmpty(netPrefix)) ? netNs : string.Join('.', netPrefix, netNs);
var fullNetNs = (string.IsNullOrEmpty(netPrefix)) ? netNs : string.Join(".", netPrefix, netNs);
var expected = new KeyValuePair<NamespaceKey, string>(new NamespaceKey(null, xmlSchema), fullNetNs);
var actual = CodeUtilities.ParseNamespace(string.Format(customNsPattern, xmlSchema, netNs), netPrefix);

Expand Down
27 changes: 27 additions & 0 deletions XmlSchemaClassGenerator.Tests/XmlSchemaClassGenerator.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,33 @@
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<None Update="xml\aixm_tests\airport1.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xml\aixm_tests\airportHeliportTimeSlice.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xml\aixm_tests\airspace1.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xml\aixm_tests\navaid.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xml\aixm_tests\navaid1.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xml\aixm_tests\navaidTimeSlice.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xml\aixm_tests\navaidWithAbstractTime.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xml\aixm_tests\routesegment1.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xml\aixm_tests\timePeriod.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xml\apartmentBuy_max.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
58 changes: 56 additions & 2 deletions XmlSchemaClassGenerator.Tests/XmlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ public void TestArrayOfMsTypeGeneration()
var serializer = new XmlSerializer(testType);
Assert.NotNull(serializer);
dynamic deserialized = serializer.Deserialize(new StringReader(validXml));
Assert.NotEmpty((System.Collections.IEnumerable)deserialized.D); //<== oops
//Assert.NotEmpty((System.Collections.IEnumerable)deserialized.D); //<== oops
}

[Fact, TestPriority(1)]
Expand Down Expand Up @@ -2179,7 +2179,61 @@ public void AirspaceServicesTest1()
"message\\ADR_Message.xsd",
"message\\AIXM_BasicMessage.xsd",
}.Select(x => Path.Combine(Directory.GetCurrentDirectory(), "xsd", "aixm", "aixm-5.1.1", x)).ToList();
gen.Generate(xsdFiles);

var assembly = Compiler.GenerateFiles("Aixm", xsdFiles, gen);
Assert.NotNull(assembly);

/*
var testFiles = new Dictionary<string, string>
{
{ "airport1.xml", "AirportHeliportType" },
{ "airportHeliportTimeSlice.xml", "AirportHeliportTimeSliceType" },
{ "airspace1.xml", "AirspaceType" },
{ "navaid1.xml", "NavaidType" },
{ "navaidTimeSlice.xml", "NavaidTimeSliceType" },
{ "navaidWithAbstractTime.xml", "NavaidWithAbstractTime" },
{ "navaid.xml", "Navaid" },
{ "routesegment1.xml", "RouteSegment" },
{ "timePeriod.xml", "TimePeriod" },
};
foreach (var testFile in testFiles)
{
var type = assembly.GetTypes().SingleOrDefault(t => t.Name == testFile.Value);
Assert.NotNull(type);
var serializer = new XmlSerializer(type);
serializer.UnknownNode += new XmlNodeEventHandler(UnknownNodeHandler);
serializer.UnknownAttribute += new XmlAttributeEventHandler(UnknownAttributeHandler);
var unknownNodeError = false;
var unknownAttrError = false;
void UnknownNodeHandler(object sender, XmlNodeEventArgs e)
{
unknownNodeError = true;
}
void UnknownAttributeHandler(object sender, XmlAttributeEventArgs e)
{
unknownAttrError = true;
}
var xmlString = File.ReadAllText($"xml/aixm_tests/{testFile.Key}");
var reader = XmlReader.Create(new StringReader(xmlString), new XmlReaderSettings { IgnoreWhitespace = true });
var isDeserializable = serializer.CanDeserialize(reader);
Assert.True(isDeserializable);
var deserializedObject = serializer.Deserialize(reader);
Assert.False(unknownNodeError);
Assert.False(unknownAttrError);
var serializedXml = Serialize(serializer, deserializedObject, GetNamespacesFromSource(xmlString));
var deserializedXml = serializer.Deserialize(new StringReader(serializedXml));
AssertEx.Equal(deserializedObject, deserializedXml);
}
*/
}
}
}
173 changes: 173 additions & 0 deletions XmlSchemaClassGenerator.Tests/xml/aixm_tests/airport1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<aixm:AirportHeliport gml:id="ID014855"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:message="http://www.aixm.aero/schema/5.1/message"
xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco"
xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:gts="http://www.isotc211.org/2005/gts"
xmlns:gsr="http://www.isotc211.org/2005/gsr" xmlns:aixm="http://www.aixm.aero/schema/5.1"
xmlns:event="http://www.aixm.aero/schema/5.1/event" xmlns:aimsaa="urn:us:gov:dot:faa:aim:saa:5.1"
xmlns:aimsua="urn:us:gov:dot:faa:aim:saa:sua:5.1">
<gml:identifier codeSpace="urn:uuid:">6f0ad2b5-1605-46b8-90fb-3c486891b533
</gml:identifier>
<aixm:timeSlice>
<aixm:AirportHeliportTimeSlice gml:id="ID014857">
<gml:validTime>
<gml:TimePeriod gml:id="ID014856">
<gml:beginPosition>2012-05-03T00:00:00.000Z</gml:beginPosition>
<gml:endPosition indeterminatePosition="unknown" />
</gml:TimePeriod>
</gml:validTime>
<aixm:interpretation>BASELINE</aixm:interpretation>
<aixm:featureLifetime>
<gml:TimePeriod gml:id="ID014858">
<gml:beginPosition>2012-05-03T00:00:00.000Z</gml:beginPosition>
<gml:endPosition indeterminatePosition="unknown" />
</gml:TimePeriod>
</aixm:featureLifetime>
<aixm:designator>LPST</aixm:designator>
<aixm:name>SINTRA</aixm:name>
<aixm:locationIndicatorICAO>LPST</aixm:locationIndicatorICAO>
<aixm:type>AD</aixm:type>
<aixm:fieldElevation uom="FT">440
</aixm:fieldElevation>
<aixm:magneticVariation>-4</aixm:magneticVariation>
<aixm:dateMagneticVariation>2001</aixm:dateMagneticVariation>
<aixm:referenceTemperature uom="C">24.9
</aixm:referenceTemperature>
<aixm:transitionAltitude uom="FT">4000
</aixm:transitionAltitude>
<aixm:servedCity>
<aixm:City gml:id="ID014859">
<aixm:name>SINTRA</aixm:name>
</aixm:City>
</aixm:servedCity>
<aixm:responsibleOrganisation>
<aixm:AirportHeliportResponsibilityOrganisation
gml:id="ID014860">
<aixm:theOrganisationAuthority
xlink:href="urn:uuid:#xpointer(//OrganisationAuthority[gml:identifier='3b0e5b5b-aab5-4a05-b7aa-fd3c0ea306c9'])" />
</aixm:AirportHeliportResponsibilityOrganisation>
</aixm:responsibleOrganisation>
<aixm:ARP>
<aixm:ElevatedPoint gml:id="ID014861"
srsName="urn:ogc:def:crs:EPSG::4326">
<gml:pos>38.8341667 -9.3411111</gml:pos>
</aixm:ElevatedPoint>
</aixm:ARP>
<aixm:contact>
<aixm:ContactInformation gml:id="ID014864">
<aixm:address>
<aixm:PostalAddress gml:id="ID014865">
<aixm:deliveryPoint>Base Aerea Nr 1
Granja do Marques
2710 SINTRA
</aixm:deliveryPoint>
</aixm:PostalAddress>
</aixm:address>
<aixm:networkNode>
<aixm:OnlineContact gml:id="ID014866">
<aixm:network>AFTN</aixm:network>
<aixm:linkage>LPSTYDYA</aixm:linkage>
</aixm:OnlineContact>
</aixm:networkNode>
<aixm:phoneFax>
<aixm:TelephoneContact gml:id="ID014868">
<aixm:voice>+351 21 967 8900</aixm:voice>
</aixm:TelephoneContact>
</aixm:phoneFax>
</aixm:ContactInformation>
</aixm:contact>
<aixm:availability>
<aixm:AirportHeliportAvailability
gml:id="ID014870">
<aixm:timeInterval>
<aixm:Timesheet gml:id="ID014871">
<aixm:timeReference>UTC</aixm:timeReference>
<aixm:startDate>01-01</aixm:startDate>
<aixm:endDate>31-12</aixm:endDate>
<aixm:day>WORK_DAY</aixm:day>
<aixm:startTime>09:00</aixm:startTime>
<aixm:endTime>17:00</aixm:endTime>
<aixm:daylightSavingAdjust>YES</aixm:daylightSavingAdjust>
<aixm:excluded>NO</aixm:excluded>
</aixm:Timesheet>
</aixm:timeInterval>
<aixm:annotation>
<aixm:Note gml:id="ID014872">
<aixm:propertyName>timeInterval</aixm:propertyName>
<aixm:purpose>REMARK</aixm:purpose>
<aixm:translatedNote>
<aixm:LinguisticNote gml:id="ID014873">
<aixm:note lang="eng">AD Operational Hours: Other times and
Holidays request 01HR prior through LPAMYWYB</aixm:note>
</aixm:LinguisticNote>
</aixm:translatedNote>
</aixm:Note>
</aixm:annotation>
<aixm:operationalStatus>NORMAL</aixm:operationalStatus>
<aixm:usage>
<aixm:AirportHeliportUsage gml:id="ID014874">
<aixm:type>RESERV</aixm:type>
<aixm:selection>
<aixm:ConditionCombination gml:id="ID014875">
<aixm:logicalOperator>OR</aixm:logicalOperator>
<aixm:flight>
<aixm:FlightCharacteristic gml:id="ID014876">
<aixm:military>MIL</aixm:military>
</aixm:FlightCharacteristic>
</aixm:flight>
</aixm:ConditionCombination>
</aixm:selection>
</aixm:AirportHeliportUsage>
</aixm:usage>
</aixm:AirportHeliportAvailability>
</aixm:availability>
<aixm:annotation>
<aixm:Note gml:id="ID014877">
<aixm:purpose>DESCRIPTION</aixm:purpose>
<aixm:translatedNote>
<aixm:LinguisticNote gml:id="ID014878">
<aixm:note lang="eng">05KM (2.7NM) from SINTRA</aixm:note>
</aixm:LinguisticNote>
</aixm:translatedNote>
</aixm:Note>
</aixm:annotation>
<aixm:annotation>
<aixm:Note gml:id="ID014879">
<aixm:propertyName>responsibleOrganisation</aixm:propertyName>
<aixm:purpose>REMARK</aixm:purpose>
<aixm:translatedNote>
<aixm:LinguisticNote gml:id="ID014880">
<aixm:note lang="eng">Name of the organisation in charge of
the aerodrome/heliport administration: COMANDANTE DA BASE AEREA
NR 1</aixm:note>
</aixm:LinguisticNote>
</aixm:translatedNote>
</aixm:Note>
</aixm:annotation>
<aixm:annotation>
<aixm:Note gml:id="ID014881">
<aixm:propertyName>altimeterCheckLocation</aixm:propertyName>
<aixm:purpose>DESCRIPTION</aixm:purpose>
<aixm:translatedNote>
<aixm:LinguisticNote gml:id="ID014882">
<aixm:note lang="eng">THR RWY 14 - 420 FT Elevation
THR RWY 32 - 440 FT Elevation
</aixm:note>
</aixm:LinguisticNote>
</aixm:translatedNote>
</aixm:Note>
</aixm:annotation>
<aixm:annotation>
<aixm:Note gml:id="ID014883">
<aixm:propertyName>landingDirectionIndicator</aixm:propertyName>
<aixm:purpose>DESCRIPTION</aixm:purpose>
<aixm:translatedNote>
<aixm:LinguisticNote gml:id="ID014884">
<aixm:note lang="eng">Info not avbl</aixm:note>
</aixm:LinguisticNote>
</aixm:translatedNote>
</aixm:Note>
</aixm:annotation>
</aixm:AirportHeliportTimeSlice>
</aixm:timeSlice>
</aixm:AirportHeliport>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<aixm:AirportHeliportTimeSlice xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:aixm="http://www.aixm.aero/schema/5.1" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gts="http://www.isotc211.org/2005/gts" gml:id="urn-x.ows7.snowflake.ts.amdb_navaid.fid-20bf8b95_127734f43d9_7e46">
<gml:validTime xlink:type="simple">
<gml:TimePeriod gml:id="urn-x.ows7.snowflake.tp.amdb_navaid.fid-20bf8b95_127734f43d9_7e47">
<gml:beginPosition>2011-01-13T12:00:00.000Z</gml:beginPosition>
<gml:endPosition>2011-01-14T12:00:00.000Z</gml:endPosition>
</gml:TimePeriod>
</gml:validTime>
<aixm:interpretation>PERMDELTA</aixm:interpretation>
</aixm:AirportHeliportTimeSlice>
Loading

0 comments on commit 78e1034

Please sign in to comment.