Thema: Delphi XML.Attributes entfernen

Einzelnen Beitrag anzeigen

Benutzerbild von Dunkel
Dunkel

Registriert seit: 26. Mär 2007
Ort: Klingenstadt
541 Beiträge
 
Delphi 2007 Enterprise
 
#1

XML.Attributes entfernen

  Alt 3. Jul 2007, 17:51
Hallo zusammen!

Seit kurzer Zeit beschäftige ich mich mit XML. Um genauer zu sein, versuche ich momentan das XSPF-Playlist-Format zu lesen & zu schreiben.

Das Lesen ist (nach einer seehhrr langen Nacht) nicht das Problem, das Schreiben im Prinzip auch nicht.

Hier ist der Test-Quelltext zum Schreiben eines XSPF-Dokuments:
Delphi-Quellcode:
var
  myXML: IXMLDocument;
  node: IXMLNode;
  i: word;
begin
  myXML := newXMLDocument;
  myXML.Options:= [doNodeAutoIndent];

  myXML.Encoding:= 'UTF-8';

  node:= myXML.AddChild('playlist');
  node.Attributes['version']:= '0';
  node.Attributes['xmlns']:= 'http://xspf.org/ns/0/';

  node:= myXML.DocumentElement.AddChild('trackList');

  for i := 1 to 5 do
    begin
      node:= myXML.DocumentElement.ChildNodes.FindNode('trackList').AddChild('track');
      node.AddChild('creator');
      node.ChildNodes.FindNode('creator').Text:= 'TestArtist'+IntToStr(i);
      node.AddChild('location');
      node.ChildNodes.FindNode('location').Text:= 'TestLocation'+IntToStr(i);
      node.AddChild('trackNum');
      node.ChildNodes.FindNode('trackNum').Text:= IntToStr(i);
    end;

  myXML.Active:= True;
  myXML.SaveToFile('D:\Test.xspf');
end;

Und so sieht die erzeugte Datei aus:
XML-Code:
<?xml version="1.0" encoding="UTF-8"?>
<playlist version="0" xmlns="http://xspf.org/ns/0/">
  <trackList xmlns="">
    <track>
      <creator>TestArtist1</creator>
      <location>TestLocation1</location>
      <trackNum>1</trackNum>
    </track>
    <track>
      <creator>TestArtist2</creator>
      <location>TestLocation2</location>
      <trackNum>2</trackNum>
    </track>
    <track>
      <creator>TestArtist3</creator>
      <location>TestLocation3</location>
      <trackNum>3</trackNum>
    </track>
    <track>
      <creator>TestArtist4</creator>
      <location>TestLocation4</location>
      <trackNum>4</trackNum>
    </track>
    <track>
      <creator>TestArtist5</creator>
      <location>TestLocation5</location>
      <trackNum>5</trackNum>
    </track>
  </trackList>
</playlist>
So weit, so gut. Das Problem ist nur, dass im Node trackList das Attribut xmlns gesetzt wird. Ich bin mir aber nicht bewusst, wo ich das in meinem Code mache.

Kann mir da jemand weiterhelfen?
Es ist zu wahr um schön zu sein...
  Mit Zitat antworten Zitat