XML: im Attributnamen fehlt ein Teil "xsi:"



  • Hallo,

    ich möchte gern folgenden Knoten erstellen:

    <root xmlns:xsi="http://www.w3.org/2001" xsi:noNamespaceSchemaLocation="http://www.bla.de">
    

    Mein Quellcode sieht so aus:

    XmlAttribute attr = XML_Datei.CreateAttribute("xsi:noNamespaceSchemaLocation");
    attr.Value = "http://www.bla.de";
    Knoten.Attributes.Append(attr);
    

    Das Problem ist, dass im Attribut das "xsi:" fehlt.

    Weiss vielleicht jemand was ich falsch mache?
    Danke


  • Administrator

    XmlAttribute attr = XML_Datei.CreateAttribute("xsi", "noNamespaceSchemaLocation", "http://www.w3.org/2001");
    attr.Value = "http://www.bla.de";
    Knoten.Attributes.Append(attr);
    

    Sollte, glaube ich, so funktionieren. Womöglich geht auch das folgende:

    XmlAttribute attr = XML_Datei.CreateAttribute("xsi:noNamespaceSchemaLocation", "http://www.w3.org/2001");
    

    Aber keine Gewähr, habe bisher nur selten mit Namensräumen in XML gearbeitet.

    Grüssli



  • Hallo Dravere,

    danke für die schnelle Antwort.

    Dein erster Vorschlag funktioniert:

    XmlAttribute attr = XML_Datei.CreateAttribute("xsi", "noNamespaceSchemaLocation", "http://www.w3.org/2001");
    attr.Value = "http://www.bla.de";
    Knoten.Attributes.Append(attr);
    

    Der Knoten sieht jetzt so aus:

    <root xsi:noNamespaceSchemaLocation="http://www.bla.de" xmlns:xsi="http://www.w3.org/2001">
    

    Im Vergleich zu

    <root xmlns:xsi="http://www.w3.org/2001" xsi:noNamespaceSchemaLocation="http://www.bla.de">
    

    Aber ich denke die Reihenfolge der Namespaceattribute dürfte keine Rolle spielen


Anmelden zum Antworten