Skip to content

The AttritubteWildcard.Namespace does not contain a value if an intersection or union is used #29120

@JosVerburg

Description

@JosVerburg

I've noticed that the AttributeWildcard.Namespace does not contain the correct value when it requires a union or intersection to be calculated.

In the code sample below I've used a schema with 2 elements. The first one el1 has a xs:anyAttribute which allows the namespaces http://foo.com and http://bar.com, since we also get a xs:anyAttribute from the attribute group group1 the intersection should be the value.
The second element shows that the AttributeWildcard.Namespace is set when no intersection needs to be done.
Describe here: https://www.w3.org/TR/xmlschema-1/#element-anyAttribute

I've noticed that the correct list of allowed namespaces is available in the internal property NamespaceList. So I'd think we could return a value based the NamespaceList instead of having a separate string. (I didn't yet look into how/when the string is set). Let me know if you'd like to see a pull request for this :)

using System;
using System.IO;
using System.Reflection;
using System.Xml.Schema;

namespace ConsoleApp1
{
	public class Program
	{
		public static void Main(string[] args)
		{
			const string xsd = @"<?xml version=""1.0""?>
<xs:schema
	xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
	<xs:element name=""el1"">
		<xs:complexType>
			<xs:attributeGroup ref=""group1""/>
				<!-- The result should be the intersection of this xs:anyAttribute and the xs:anyAttribute of group1 -->
				<xs:anyAttribute namespace=""http://foo.com http://bar.com""/>
		</xs:complexType>
	</xs:element>
	<xs:element name=""el2"">
		<xs:complexType>
			<xs:attributeGroup ref=""group1""/>
		</xs:complexType>
	</xs:element>
	<xs:attributeGroup name=""group1"">
		<xs:anyAttribute namespace=""http://foo.com""/>
	</xs:attributeGroup>
</xs:schema>";
			XmlSchema schema;
			using (var reader = new StringReader(xsd))
				schema = XmlSchema.Read(reader, (sender, e) =>
				{
					throw e.Exception;
				});

			var schemaSet = new XmlSchemaSet();
			schemaSet.Add(schema);
			schemaSet.Compile();

			foreach (XmlSchemaElement element in schemaSet.GlobalElements.Values)
			{
				Console.WriteLine($"====={element.Name}=====");
				var attributeWildcard = ((XmlSchemaComplexType)element.ElementSchemaType).AttributeWildcard;
				Console.WriteLine("Public property:   " + (attributeWildcard.Namespace ?? "AttriubteWildcard does not contain the calculated namespace :("));
				var namespaceList = attributeWildcard.GetType().GetProperty("NamespaceList", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(attributeWildcard);
				Console.WriteLine("Internal property: " + namespaceList);
			}
			// Outputs:
			// =====el1=====
			// Public property:   AttriubteWildcard does not contain the calculated namespace :(
			// Internal property: http://foo.com
			// =====el2=====
			// Public property:   http://foo.com
			// Internal property: http://foo.com
		}
	}
}

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions