In Xml-Datei Schemainformationen hinzufügen

colblake

Erfahrenes Mitglied
Hallo,

ich versuche gerade in eine neue XML-Datei folgende Informationen (speziell die Attribute) mit den dotnet eigenen Mitteln hinzuzufügen:
XML:
...
<Document xmlns="blabla" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "urn:swift:xsd:$pain... .xsd">
...

doch leider klappt das nicht. Ich bin auch jetzt nicht so gut was namespaces und Schemas betrifft.

Mein derzeitiger Ansatz ist:
C#:
...
XmlAttribute a = doc.CreateAttribute("xsi", "http://");
XmlElement documentNode = doc.CreateElement("Document");
documentNode.Attributes.Append(a);
doc.AppendChild(documentNode);
...

und raus kommt:
XML:
<Document d1p1:xsi="" xmlns:d1p1="http://">


help ;)
gruß
Col.Blake
 
Hi.

xsi == Namensraum-Präfix
schemaLocation == Attribut-Name
C#:
// entweder
var a = doc.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
// oder
var a = doc.CreateAttribute("xsi:schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");

a.Value = "urn:swift:xsd:$pain... .xsd";
Gruß
 

Neue Beiträge

Zurück