XMLUtilJS - 전역
스크립트와 함께 검색 사용할 JavaScript용 XML 유틸리티를 제공합니다.
XMLUtilJS API는 플러그인과 함께 검색 제공됩니다. XML 유틸리티가 필요한 모든 서버 쪽 검색 스크립트에서 이 스크립트 포함을 사용합니다.
정적 변수 XMLUtilJS를 사용하여 이러한 메서드에 액세스합니다.
XMLUtilJS - escapeForXMLText(텍스트 문자열)
지정된 문자열에 대한 이스케이프 텍스트를 제공합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 텍스트 | 문자열 | 서식을 지정할 텍스트입니다. |
| 유형 | 설명 |
|---|---|
| 문자열 | 서식이 지정된 텍스트입니다. |
다음 예제에서는 문서에서 이스케이프된 XML 데이터를 나열하는 방법을 보여 줍니다. 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);
출력:
<?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)
문자열을 XML 값으로 변환합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| STR | 문자열 | 변환할 문자열입니다. |
| 유형 | 설명 |
|---|---|
| 문자열 | XML로 변환된 지정된 문자열입니다. |
다음 예제에서는 이스케이프된 XML의 문자열을 태그가 지정된 XML 출력으로 변환하는 방법을 보여 줍니다. 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);
출력:
<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(문자열 텍스트)
지정된 문자열에 대해 이스케이프되지 않은 XML을 제공합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 텍스트 | 문자열 | 정리할 XML 텍스트입니다. |
| 유형 | 설명 |
|---|---|
| 문자열 | 정리된 XML 문자열입니다. |
다음 예제에서는 이스케이프된 XML 문자열을 태그가 지정된 XML 출력으로 변환하는 방법을 보여 줍니다. 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);
출력:
<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(문자열 XMLvalue)
XML 값을 문자열로 변환합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| XML값 | 문자열 | 변환할 XML |
| 유형 | 설명 |
|---|---|
| 문자열 | 문자열로 변환된 XML 값입니다. |
다음 예제에서는 XML 문서를 문자열로 변환하는 방법을 보여 줍니다.
//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);
출력:
<?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>