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

 Release :

    - yokohama

ft:locale :

    - de-DE

ft:publication_title :

    - Yokohama-API-Referenz

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# XMLUtilJS -- Global

# XMLUtilJS -- Global {#ariaid-title1}

* Freigeben Version: Yokohama
* 
* Aktualisiert 30. Januar 2025
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 Minuten Lesedauer

Die XMLUtilJS Die Skripteinbindung stellt XML-Dienstprogrammmethoden für JavaScript zur Verwendung bereit DiscoverySkripts.

Diese Skripteinbindung wird mit bereitgestellt DiscoveryPlugin. Verwenden Sie diese Skripteinbindung auf einer beliebigen serverseitigen Seite DiscoverySkript, in dem Sie XML-Dienstprogramme benötigen.

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

## XMLUtilJS -- escapeForXMLText (Zeichenfolgentext) {#ariaid-title2}

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

| Name | Typ | Beschreibung |
|-|-|-|
| HTML | Zeichenfolge | Der zu formatierende 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 | Der formatierte Text. |
[Tabelle : 2. Rückgaben]

{#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 ZeichenfolgenToWert() .

    // 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. Rückgaben]

{#r_XUJ-stringToValue_S__table_ftz_b3s_pt}  
Das folgende Beispiel zeigt, wie eine Zeichenfolge von XML mit Escape-Zeichen in XML-Ausgabe mit Tags 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 (Zeichenfolgentext) {#ariaid-title4}

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

| Name | Typ | Beschreibung |
|-|-|-|
| HTML | 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. Rückgaben]

{#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(Zeichenfolge XmlValue) {#ariaid-title5}

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

| Name | Typ | Beschreibung |
|-|-|-|
| XmlWert | Zeichenfolge | Die 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 | Der in eine Zeichenfolge konvertierte XML-Wert. |
[Tabelle : 8. Rückgaben]

{#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>


