Skip to content

Commit

Permalink
Xml use strongly typed struct enumerators (#32296)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Feb 14, 2020
1 parent 4107a4c commit 9ac0abb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
Expand Down Expand Up @@ -673,19 +674,20 @@ internal void AddDefaultAttributes(XmlElement elem)
SchemaElementDecl ed = GetSchemaElementDecl(elem);
if (ed != null && ed.AttDefs != null)
{
IDictionaryEnumerator attrDefs = ed.AttDefs.GetEnumerator();
while (attrDefs.MoveNext())
foreach (KeyValuePair<XmlQualifiedName, SchemaAttDef> attrDefs in ed.AttDefs)
{
SchemaAttDef attdef = (SchemaAttDef)attrDefs.Value;
SchemaAttDef attdef = attrDefs.Value;
if (attdef.Presence == SchemaDeclBase.Use.Default ||
attdef.Presence == SchemaDeclBase.Use.Fixed)
{
//build a default attribute and return
string attrPrefix = string.Empty;
string attrPrefix;
string attrLocalname = attdef.Name.Name;
string attrNamespaceURI = string.Empty;
if (schInfo.SchemaType == SchemaType.DTD)
{
attrPrefix = attdef.Name.Namespace;
}
else
{
attrPrefix = attdef.Prefix;
Expand Down Expand Up @@ -1687,10 +1689,9 @@ internal XmlAttribute GetDefaultAttribute(XmlElement elem, string attrPrefix, st
SchemaElementDecl ed = GetSchemaElementDecl(elem);
if (ed != null && ed.AttDefs != null)
{
IDictionaryEnumerator attrDefs = ed.AttDefs.GetEnumerator();
while (attrDefs.MoveNext())
foreach (KeyValuePair<XmlQualifiedName, SchemaAttDef> attrDefs in ed.AttDefs)
{
SchemaAttDef attdef = (SchemaAttDef)attrDefs.Value;
SchemaAttDef attdef = attrDefs.Value;
if (attdef.Presence == SchemaDeclBase.Use.Default ||
attdef.Presence == SchemaDeclBase.Use.Fixed)
{
Expand Down
28 changes: 11 additions & 17 deletions src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,27 +655,21 @@ private void LoadDocumentType(IDtdInfo dtdInfo, XmlDocumentType dtNode)
_doc.Entities = dtNode.Entities;

//extract the elements which has attribute defined as ID from the element declarations
IDictionaryEnumerator elementDecls = schInfo.ElementDecls.GetEnumerator();
if (elementDecls != null)
foreach (KeyValuePair<XmlQualifiedName, SchemaElementDecl> elementDecls in schInfo.ElementDecls)
{
elementDecls.Reset();
while (elementDecls.MoveNext())
SchemaElementDecl elementDecl = elementDecls.Value;
if (elementDecl.AttDefs != null)
{
SchemaElementDecl elementDecl = (SchemaElementDecl)elementDecls.Value;
if (elementDecl.AttDefs != null)
foreach (KeyValuePair<XmlQualifiedName, SchemaAttDef> attDefs in elementDecl.AttDefs)
{
IDictionaryEnumerator attDefs = elementDecl.AttDefs.GetEnumerator();
while (attDefs.MoveNext())
SchemaAttDef attdef = attDefs.Value;
if (attdef.Datatype.TokenizedType == XmlTokenizedType.ID)
{
SchemaAttDef attdef = (SchemaAttDef)attDefs.Value;
if (attdef.Datatype.TokenizedType == XmlTokenizedType.ID)
{
//we only register the XmlElement based on their Prefix/LocalName and skip the namespace
_doc.AddIdInfo(
_doc.AddXmlName(elementDecl.Prefix, elementDecl.Name.Name, string.Empty, null),
_doc.AddAttrXmlName(attdef.Prefix, attdef.Name.Name, string.Empty, null));
break;
}
//we only register the XmlElement based on their Prefix/LocalName and skip the namespace
_doc.AddIdInfo(
_doc.AddXmlName(elementDecl.Prefix, elementDecl.Name.Name, string.Empty, null),
_doc.AddAttrXmlName(attdef.Prefix, attdef.Name.Name, string.Empty, null));
break;
}
}
}
Expand Down

0 comments on commit 9ac0abb

Please sign in to comment.