Exemple #1
0
        public static void parseXmlFile(string filename, XML_SaxParserComponent mainComponent)
        {
            XML_SaxParserDelegator delegator = new XML_SaxParserDelegator(mainComponent);

            XmlTextReader reader = new XmlTextReader(filename);

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element: // The node is an element.

                    List <XML_Attribute> attributes = new List <XML_Attribute>();

                    if (reader.HasAttributes)
                    {
                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);

                            XML_Attribute attribute = new XML_Attribute();
                            attribute._name  = reader.Name;
                            attribute._value = reader.Value;

                            attributes.Add(attribute);
                        }
                        reader.MoveToElement(); //Moves the reader back to the element node.
                    }

                    if (reader.IsEmptyElement)
                    {
                        delegator.startElement(reader.Name, attributes);
                        delegator.endElement(reader.Name);
                    }
                    else
                    {
                        delegator.startElement(reader.Name, attributes);
                    }

                    break;

                case XmlNodeType.Text: //Display the text in each element.
                    //Debug.LogWarning(reader.Value);
                    break;

                case XmlNodeType.EndElement: //Display the end of the element.

                    delegator.endElement(reader.Name);
                    break;
                }
            }
        }
    public static void parseXmlFile( string filename, XML_SaxParserComponent mainComponent )
    {
      XML_SaxParserDelegator delegator = new XML_SaxParserDelegator(mainComponent);

      XmlTextReader reader = new XmlTextReader(filename);
      while (reader.Read())
      {
        switch (reader.NodeType)
        {
          case XmlNodeType.Element: // The node is an element.

           List<XML_Attribute> attributes = new List<XML_Attribute>();

           if (reader.HasAttributes)
           {
             for (int i = 0; i < reader.AttributeCount; i++)
             {
               reader.MoveToAttribute(i);

               XML_Attribute attribute = new XML_Attribute();
               attribute._name = reader.Name;
               attribute._value = reader.Value;

               attributes.Add(attribute);
             }
             reader.MoveToElement(); //Moves the reader back to the element node.
           }

           if (reader.IsEmptyElement)
            {
              delegator.startElement( reader.Name, attributes );
              delegator.endElement( reader.Name );
            }
            else
            {
              delegator.startElement( reader.Name, attributes );
            }

            break;
          case XmlNodeType.Text: //Display the text in each element.
            //Debug.LogWarning(reader.Value);
            break;
          case XmlNodeType.EndElement: //Display the end of the element.

            delegator.endElement( reader.Name );
            break;
        }
      }
    }