Example #1
0
 /**
  * Initialisiert einen neuen Knoten.
  * @param typ Der Typ
  * @param name Der Elementname
  * @param text Der Elementtext oder Leerstring, falls das Element keinen Text hat.
  * @param attrs Die Attribute des Elements oder eine leere Map, falls das Element
  * keine Attribute hat.
  */
 public Knoten(KnotenTyp typ, String name, String text, EqualsDictionary <string, string> attrs)
 {
     if (attrs == null)
     {
         throw new ArgumentNullException("attrs");
     }
     this.typ         = typ;
     this.elementName = name;
     this.text        = text;
     this.attributes  = attrs;
 }
Example #2
0
        /**
         * Erzeugt aus dem angegebenen Node einen Knoten. Die Kinder werden dabei <b>nicht</b>
         * berücksichtigt.
         * @param node Der zu konvertierende Node.
         * @return Ein Knoten, der dem Node entspricht.
         */

        private static Knoten createKnoten(XmlNode node)
        {
            String name = node.Name;

            String text = getTextContent(node);

            KnotenTyp typ;

            if (node.NodeType == XmlNodeType.Element)
            {
                typ = KnotenTyp.ELEMENT;
            }
            else if (node.NodeType == XmlNodeType.Text)
            {
                typ = KnotenTyp.TEXT;
                if (string.IsNullOrEmpty(text.Trim()))
                {
                    //Whitespace ignorieren
                    return(null);
                }
            }
            else
            {
                return(null);
                //wird nicht unterstützt
            }

            EqualsDictionary <string, string> attrs = new EqualsDictionary <string, string>();
            XmlAttributeCollection            nnm   = node.Attributes;

            if (nnm != null)
            {
                Debug.Assert(typ != KnotenTyp.TEXT);
                for (int i = 0; i < nnm.Count; i++)
                {
                    XmlNode attr = nnm.Item(i);

                    String attrName  = attr.Name;
                    String attrValue = attr.Value;
                    Debug.Assert(attr.NodeType == XmlNodeType.Attribute);
                    attrs.Add(attrName, attrValue);
                }
            }

            return(new Knoten(typ, name, text, attrs));
        }