Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
.idea/
Original file line number Diff line number Diff line change
Expand Up @@ -518,41 +518,49 @@ private static void AddXmlnsAndChangePrefixReferenced(
IEnumerable<XElement> newElements,
Dictionary<string, string> namespaces)
{
// Capture all declared xmlns attributes
var parentNamespaces = documentElement
.Attributes()
.Where(a => a.ToString()
.Contains("xmlns:"))
.Select(a => new
{
Prefix = a.Name.LocalName,
Namespace = a.Value
}).ToDictionary(a => a.Namespace, a => a.Prefix);
.Attributes()
.Where(a => a.IsNamespaceDeclaration)
.Select(a => new { Prefix = a.Name.LocalName, Namespace = a.Value })
.ToDictionary(a => a.Namespace + "_" + a.Prefix, a => a.Prefix); // composite key

foreach (var item in namespaces)
{
//string prefix = string.Empty;
parentNamespaces.TryGetValue(item.Key, out string prefix);

if (prefix == null)
string desiredPrefix = item.Value;
string prefix = null;
var attr = documentElement.Attribute(XNamespace.Xmlns + desiredPrefix);
if (attr != null)
{
prefix = GenerateNewNamespace(documentElement, parentNamespaces, item);
if (attr.Value == item.Key)
{
prefix = desiredPrefix;
}
else
{
prefix = GenerateNewNamespace(documentElement, parentNamespaces, item);
}
}
else
{
documentElement.Add(new XAttribute(XNamespace.Xmlns + desiredPrefix, item.Key));
parentNamespaces.Add(item.Key + "_" + desiredPrefix, desiredPrefix);
prefix = desiredPrefix;
}

//Modify attributes from elements with the same prefix
// Modify attributes from elements that reference the old prefix
var prefixValue = item.Value + ":";

foreach (var element in newElements.DescendantsAndSelf())
{
//Go through all attributes and modify if they have the prefix
// Go through all attributes and modify if they have the prefix
var attributes = element
.Attributes()
.Where(e => e.Value.Contains(prefixValue));

.Attributes()
.Where(e => e.Value.Contains(prefixValue));
foreach (var attribute in attributes)
{
if (attribute.Value.Count(i => i == ':') == 1
&& !(Uri.TryCreate(attribute.Value, UriKind.Absolute, out var uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps)))
&& !(Uri.TryCreate(attribute.Value, UriKind.Absolute, out var uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps)))
{
var splitValue = attribute.Value.Split(':');
attribute.Value = prefix + ":" + splitValue[1];
Expand Down
5 changes: 5 additions & 0 deletions examples/includeExample/additional.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com/additional"
targetNamespace="http://example.com/additional">
<xsd:element name="AdditionalElement" type="xsd:string"/>
</xsd:schema>
5 changes: 5 additions & 0 deletions examples/includeExample/common.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com/common"
targetNamespace="http://example.com/common">
<xsd:element name="CommonElement" type="xsd:string"/>
</xsd:schema>
41 changes: 41 additions & 0 deletions examples/includeExample/example.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://example.com/wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
targetNamespace="http://example.com/wsdl">
<types>
<xsd:schema>
<xsd:import namespace="http://example.com/schema1" schemaLocation="schema1.xsd"/>
<xsd:import namespace="http://example.com/schema2" schemaLocation="schema2.xsd"/>
</xsd:schema>
</types>
<message name="ExampleRequest">
<part name="parameters" element="tns:ExampleElement"/>
</message>
<message name="ExampleResponse">
<part name="parameters" element="tns:ExampleElement"/>
</message>
<portType name="ExamplePortType">
<operation name="ExampleOperation">
<input message="tns:ExampleRequest"/>
<output message="tns:ExampleResponse"/>
</operation>
</portType>
<binding name="ExampleBinding" type="tns:ExamplePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="ExampleOperation">
<soap:operation soapAction="http://example.com/ExampleOperation"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ExampleService">
<port name="ExamplePort" binding="tns:ExampleBinding">
<soap:address location="http://example.com/ExampleService"/>
</port>
</service>
</definitions>
11 changes: 11 additions & 0 deletions examples/includeExample/schema1.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com/schema1"
targetNamespace="http://example.com/schema1">
<xsd:import namespace="http://example.com/common" schemaLocation="common.xsd"/>
<xsd:element name="ExampleElement" type="tns:ExampleType"/>
<xsd:complexType name="ExampleType">
<xsd:sequence>
<xsd:element name="exampleField" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
12 changes: 12 additions & 0 deletions examples/includeExample/schema2.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://example.com/schema2"
targetNamespace="http://example.com/schema2">
<xsd:import namespace="http://example.com/common" schemaLocation="common.xsd"/>
<xsd:include schemaLocation="additional.xsd"/>
<xsd:element name="ExampleElement" type="tns:ExampleType"/>
<xsd:complexType name="ExampleType">
<xsd:sequence>
<xsd:element name="exampleField" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>