---
sourceDocument: Xanadu-API-Referenz
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/de-DE/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - de-DE

ft:publication_title :

    - Xanadu-API-Referenz

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# XMLUtilJS : Global

# XMLUtilJS : Global {#ariaid-title1}

* Freigeben Version: Xanadu
* 
* Aktualisiert 1. August 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 Minuten Lesedauer

Die XMLUtilJS-Skripteinbindung stellt XML-Dienstprogrammmethoden für JavaScript zur Verwendung mit Discovery -Skripts bereit.

Diese Skripteinbindung wird mit dem Plugin Discovery bereitgestellt. Verwenden Sie diese Skripteinbindung in einem beliebigen serverseitigen Skript Discovery, in dem Sie XML-Dienstprogramme benötigen.

Greifen Sie auf diese Methoden mit der statischen Variablen XMLUtilJS zu.

## XMLUtilJS -- escapeForXMLText(String text) {#ariaid-title2}

Stellt Escape-Text für eine bestimmte Zeichenfolge bereit.
{#r_XUJ-escapeForXMLText_S__table_upj_wfs_pt__entry__3}

| Name | Typ | Beschreibung |
|-|-|-|
| text | Zeichenfolge | Zu formatierender Text. |
[Tabelle : 1. Parameter]

{#r_XUJ-escapeForXMLText_S__table_upj_wfs_pt} {#r_XUJ-escapeForXMLText_S__table_vpj_wfs_pt__entry__2}

| Typ | Beschreibung |
|-|-|
| Zeichenfolge | Formatierter Text. |
[Tabelle : 2. Ergebnisse]

{#r_XUJ-escapeForXMLText_S__table_vpj_wfs_pt}  
Das folgende Beispiel zeigt, wie XML-Daten mit Escape-Zeichen in einem Dokument aufgelistet werden. Siehe auch „stringToValue()".

    // Create an XML document to work with
    var doc = new XMLDocument2();

    // Add an element called catalog
    var catalog = doc.createElement('catalog');

    // Set current element to the one previously made to add more elements
    doc.setCurrentElement(catalog);

    // Add an element called catalog
    var bookAttribute = doc.createElement('book');

    // Add an attribute to the element created
    bookAttribute.setAttribute('id', 'bk101');

    // Create multiple elements with a defined value
    doc.createElementWithTextValue('author', 'Gambardella, Matthew');
    doc.createElementWithTextValue('title', 'XML Developer');
    doc.createElementWithTextValue('genre', 'Computer');
    doc.createElementWithTextValue('price', '44.95');

    // Pass the created XML document as a string to the XMLUtilJS API function
    var escapedXML = XMLUtilJS.escapeForXMLText(doc.toString());

    // Print the escapedXML. If an invalid XML is created, the original value will be returned
    gs.print(escapedXML);

Ausgabe:

    <?xml version="1.0" encoding="UTF-8"?><catalog><book id="bk101"/><author>Gambardella, Matthew</author><title>XML Developer</title><genre>Computer</genre><price>44.95</price></catalog>

## XMLUtilJS -- stringToValue(String str) {#ariaid-title3}

Konvertiert eine Zeichenfolge in einen XML-Wert.
{#r_XUJ-stringToValue_S__table_etz_b3s_pt__entry__3}

| Name | Typ | Beschreibung |
|-|-|-|
| str | Zeichenfolge | Die zu konvertierende Zeichenfolge. |
[Tabelle : 3. Parameter]

{#r_XUJ-stringToValue_S__table_etz_b3s_pt} {#r_XUJ-stringToValue_S__table_ftz_b3s_pt__entry__2}

| Typ | Beschreibung |
|-|-|
| Zeichenfolge | Die angegebene Zeichenfolge wurde in XML konvertiert. |
[Tabelle : 4. Ergebnisse]

{#r_XUJ-stringToValue_S__table_ftz_b3s_pt}  
Das folgende Beispiel zeigt, wie eine Zeichenfolge von mit Escape-Zeichen versehener XML-Datei in eine mit Tags markierte XML-Ausgabe umgewandelt wird. Siehe auch EscapeForXMLText().

    //Example of an escaped XML string, previously generated by XMLUtilJS.escapeForXMLText()
    var escapedXML = '<catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer\'s Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description></book></catalog>';

    //Pass in escaped XML text and store output in a variable
    var output = XMLUtilJS.stringToValue(escapedXML);

    // If the input value is a string value of NULL, the output will be null, otherwise an unescaped XML string value.
    gs.print(output);

Ausgabe:

    <catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description></book></catalog>

## XMLUtilJS -- unescapeForXMLText(String text) {#ariaid-title4}

Stellt XML ohne Escape-Zeichen für eine bestimmte Zeichenfolge bereit.
{#r_XUJ-unescapeForXMLText_S__table_in5_pgs_pt__entry__3}

| Name | Typ | Beschreibung |
|-|-|-|
| text | Zeichenfolge | Der zu bereinigende XML-Text. |
[Tabelle : 5. Parameter]

{#r_XUJ-unescapeForXMLText_S__table_in5_pgs_pt} {#r_XUJ-unescapeForXMLText_S__table_jn5_pgs_pt__entry__2}

| Typ | Beschreibung |
|-|-|
| Zeichenfolge | Die bereinigte XML-Zeichenfolge. |
[Tabelle : 6. Ergebnisse]

{#r_XUJ-unescapeForXMLText_S__table_jn5_pgs_pt}  
Das folgende Beispiel zeigt, wie eine XML-Zeichenfolge mit Escape-Zeichen in eine XML-Ausgabe mit Tags konvertiert wird. Siehe auch EscapeForXMLText().

    //Example of an escaped XML string, previously generated by XMLUtilJS.escapeForXMLText()
    var escapedXML = '<catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer\'s Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description></book></catalog>';

    //Pass in escaped XML text and store output in a variable
    var output = XMLUtilJS.unescapeForXMLText(escapedXML);


    //Print the escapedXML. If the XML is invalid, the original value will be returned
    gs.print(output);

Ausgabe:

    <catalog><book id="bk101"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description></book></catalog>

## XMLUtilJS -- valueToString(String XMLvalue) {#ariaid-title5}

Konvertiert einen XML-Wert in eine Zeichenfolge.
{#r_XUJ-valueToString_S__table_ix2_4hs_pt__entry__3}

| Name | Typ | Beschreibung |
|-|-|-|
| XMLvalue | Zeichenfolge | Zu konvertierende XML |
[Tabelle : 7. Parameter]

{#r_XUJ-valueToString_S__table_ix2_4hs_pt} {#r_XUJ-valueToString_S__table_jx2_4hs_pt__entry__2}

| Typ | Beschreibung |
|-|-|
| Zeichenfolge | In eine Zeichenfolge konvertierter XML-Wert. |
[Tabelle : 8. Ergebnisse]

{#r_XUJ-valueToString_S__table_jx2_4hs_pt}  
Das folgende Beispiel zeigt, wie ein XML-Dokument in eine Zeichenfolge konvertiert wird.

    //Create an XML document to work with
    var doc = new XMLDocument2();

    //Add an element called catalog
    var catalog = doc.createElement("catalog");

    //Set our current element to the one previously made to add further elements
    doc.setCurrentElement(catalog);

    //Add an element called catalog
    var bookAttribute = doc.createElement("book");

    //Add an attribute to the element created
    bookAttribute.setAttribute("id" , "bk101");

    //create multiple elements with a defined value
    doc.createElementWithTextValue("author" , "Gambardella, Matthew");
    doc.createElementWithTextValue("title" , "XML Developer");
    doc.createElementWithTextValue("genre" , "Computer");
    doc.createElementWithTextValue("price" , "44.95");

    //Pass the created XML document as a string to the XMLUtilJS API function.
    var escapedXML = XMLUtilJS.valueToString(doc.toString());

    // Print the results
    // Returns NULL if XML is invalid
    gs.print(escapedXML);

Ausgabe:

    <?xml version="1.0" encoding="UTF-8"?><catalog><book id="bk101"/><author>Gambardella, Matthew</author><title>XML Developer</title><genre>Computer</genre><price>44.95</price></catalog>


