Zum Hauptinhalt springen

XmlSerializerResult

warnung

Eine Instanz dieser Klasse wird als Ergebnis der serialize Funktion in der XmlSerializer Klasse zurückgegeben.
In den meisten Fällen sollte dies auch reichen 😉.

constructor

new XmlSerializerResult(
document: DOMDocument,
parser?: DOMParser
): XmlSerializerResult

Parameter:

  • document: DOMDocument: Das DOMDocument
  • domParser?: DOMParser: Klasse für DOMParser (IoC) (Optional)

Beispiel:

context.enableModules();
const { XmlSerializerResult } = require("ou.sp.XmlSerializer");
const result = new XmlSerializerResult(document);

Instanz Funktionen

getRootElement : DOMElement

getRootElement(): DOMElement

Gibt das aktuelle Root Element zurück.

getDocument : DOMDocument

getDocument(): DOMDocument

Gibt das aktuelle DOM Dokument zurück.

save : boolean

save(path: string = "", encoding: SerializableEncodings = "UTF-8", prettyPrint: boolean = true): boolean

Parameter:

  • path: string = "": Pfad zur Ziel XML-Datei
  • encoding: string = "UTF-8": Verwendetes Encoding für XML-Datei
    • Mögliche Werte:
      "ASCII"
      "UTF-8"
      "UTF-16"
      "ISO-8859-1"
      "Windows-1252"
  • prettyPrint: boolean = true: Soll die XML im leserlichen Format (Zeilenumbrüche und Einrückungen) erstellt werden.

toString : string

toString(): string

Gibt das DOMDocument als XML -String zurück.

context.enableModules();
const { XmlSerializerResult } = require("ou.sp.XmlSerializer");
const result = new XmlSerializerResult(document);

// Result as XML-String
const xml = result.toString();
/*
<root>
<node1>Test1</node1>
<node2>Test2</node2>
</root>
*/