XMLUtilJS – Global
Die XMLUtilJS Die Skripteinbindung stellt XML-Dienstprogrammmethoden für JavaScript bereit, mit denen JavaScript verwendet werden soll Discovery Skripts.
Diese Skripteinbindung wird mit bereitgestellt Discovery Plugin. Verwenden Sie diese Skripteinbindung auf einer beliebigen serverseitigen Seite Discovery Skript, in dem Sie XML-Dienstprogramme benötigen.
Greifen Sie auf diese Methoden mit der statischen Variablen XMLUtilJS zu.
XMLUtilJS – escapeForXMLText(String text)
Stellt Escape-Text für eine bestimmte Zeichenfolge bereit.
| Name | Typ | Beschreibung |
|---|---|---|
| text | Zeichenfolge | Zu formatierender Text. |
| Typ | Beschreibung |
|---|---|
| Zeichenfolge | Formatierter Text. |
Das folgende Beispiel zeigt, wie XML-Daten mit Escape-Zeichen in einem Dokument aufgelistet werden. Siehe auch Zeichenfolge ToValue() .
// 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)
Konvertiert eine Zeichenfolge in einen XML-Wert.
| Name | Typ | Beschreibung |
|---|---|---|
| str | Zeichenfolge | Die zu konvertierende Zeichenfolge. |
| Typ | Beschreibung |
|---|---|
| Zeichenfolge | Die angegebene Zeichenfolge wurde in XML konvertiert. |
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(String text)
Stellt XML ohne Escape für eine bestimmte Zeichenfolge bereit.
| Name | Typ | Beschreibung |
|---|---|---|
| text | Zeichenfolge | Der zu bereinigende XML-Text. |
| Typ | Beschreibung |
|---|---|
| Zeichenfolge | Die bereinigte XML-Zeichenfolge. |
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)
Konvertiert einen XML-Wert in eine Zeichenfolge.
| Name | Typ | Beschreibung |
|---|---|---|
| XMLvalue | Zeichenfolge | Zu konvertierende XML |
| Typ | Beschreibung |
|---|---|
| Zeichenfolge | In eine Zeichenfolge konvertierter XML-Wert. |
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>