示例#1
0
 private void TraverseXsdElements(XmlSchemaObject xmlObject, XsdElement parentElement, bool recursive)
 {
     if (xmlObject is XmlSchema xmlSchema)
     {
         foreach (XmlSchemaObject element in xmlSchema.Elements.Values)
         {
             TraverseXsdElements(element, null, recursive);
         }
     }
     else if (xmlObject is XmlSchemaElement xmlElement)
     {
         if (xmlElement.ElementSchemaType is XmlSchemaSimpleType)
         {
             AddNewXsdElement(xmlElement, parentElement);
         }
         else if (xmlElement.ElementSchemaType is XmlSchemaComplexType xmlComplexType)
         {
             var element = AddNewXsdElement(xmlElement, parentElement);
             if (element != null && xmlComplexType.ContentTypeParticle != null && recursive)
             {
                 TraverseXsdElements(xmlComplexType.ContentTypeParticle, element, recursive);
             }
         }
     }
     else if (xmlObject is XmlSchemaGroupBase xmlGroup && recursive)
     {
         foreach (XmlSchemaObject item in xmlGroup.Items)
         {
             TraverseXsdElements(item, parentElement, recursive);
         }
     }
 }
示例#2
0
 private XsdElement AddNewXsdElement(XmlSchemaElement xmlSchemaElement, XsdElement element)
 {
     if (!string.IsNullOrEmpty(xmlSchemaElement.Name))
     {
         var newElement = new XsdElement(xmlSchemaElement);
         if (element == null)
         {
             elements.Add(newElement);
         }
         else
         {
             element.Children.Add(newElement);
         }
         return(newElement);
     }
     return(null);
 }