ai.xml
함수
방법 | 매개변수 | 반품 | 설명 |
|---|---|---|---|
createFromUrl(url, 메서드, 본문, 헤더, 콜백) 2018.3 기준 사용가능 | url: 문자열 유효한 URL 메서드: 문자열 유효한 HTTP 메서드 body: 문자열 요청 본문 headers: 문자열 HTTP 헤더 콜백: 오브젝트 A 함수 | ai.xml.sax | XML 스트림을 구문분석할 수 있는 XML SAX 파서 오브젝트를 생성합니다. |
createFromUrlWithAuthorization(url, 메서드, 본문, 헤더, 콜백) 2018.3 기준 사용가능 | url: 문자열 유효한 URL 메서드: 문자열 유효한 HTTP 메서드 body: 문자열 요청 본문 headers: 문자열 HTTP 헤더 콜백: 오브젝트 A 함수 | ai.xml.sax | OAuth를 사용하여 권한 부여가 있는 XML 스트림을 파싱할 수 있는 XML SAX 파서 오브젝트를 생성합니다. |
createParser() | ai.xml.parser | XML 문자열을 파싱할 수 있는 XML 파서 오브젝트를 생성합니다. | |
createDocument() | ai.xml.document | XML 문서를 생성합니다. | |
createDocType( xmlStr ) |
| ai.xml.docType | doctype을 정의하기 위해 XML 문서에 추가되는 doctype 오브젝트를 생성합니다. |
create요소( name ) |
| ai.xml.element | XML 문서에 추가할 수 있는 XML 문서의 기본 구성요소인 XML 요소를 생성합니다. |
createAttribute( name, value ) |
| ai.xml.attribute | XML 요소에 추가할 수 있는 특성 오브젝트를 생성합니다. |
- 예
- // Construct the sample XML request below /* <request> <control> <senderid>adaptiveplanning</senderid> <password>Bts9DrRkeZ</password> <controlid>SomeRandomThingToMatchToResponse</controlid> <dtdversion>3.0</dtdversion> </control> </request> */ // create XML document var doc = ai.xml.createDocument(); // create root element var requestEl = ai.xml.createElement('request'); // create control element var controlEl = ai.xml.createElement('control'); //create senderid element var senderIdEl = ai.xml.createElement('senderid'); senderIdEl.setText('adaptiveplanning'); //add <senderid> to <control> element controlEl.addChildElement(senderIdEl); //create password element var controlPasswordEl = ai.xml.createElement('password'); controlPasswordEl.setText('Bts9DrRkeZ'); //add <password> to <control> element controlEl.addChildElement(controlPasswordEl); //create controlid element var controlIdEl = ai.xml.createElement('controlid'); controlIdEl.setText('SomeRandomThingToMatchToResponse'); //add <controlid> to <control> element controlEl.addChildElement(controlIdEl); //create dtdversion element var dtdEl = ai.xml.createElement('dtdversion'); dtdEl.setText('3.0'); //add <dtdversion> to <control> element controlEl.addChildElement(dtdEl); //add <control> element to the main <request> element requestEl.addChildElement(controlEl); //set <request> as the doc's root element doc.setRootElement(requestEl);
ai.xml.sax
방법 | 매개변수 | 반품 | 설명 |
|---|---|---|---|
createFromText() | XML:string 인코딩: UTF8 콜백: 함수가 있는 오브젝트 | ai.xml.sax | XML 텍스트를 파싱할 수 있는 XML SAX 파서 오브젝트를 생성합니다.
250만 자로 제한됩니다. |
createFromUrl() | url: 문자열 유효한 URL 메서드: 문자열 유효한 HTTP 메서드 body: 문자열 요청 본문 headers: 문자열 HTTP 헤더 콜백: 함수가 있는 오브젝트 | ai.xml.sax | XML 스트림을 구문분석할 수 있는 XML SAX 파서 오브젝트를 생성합니다. |
createFromUrlWithAuthorisation() | url: 문자열 유효한 URL 메서드: 문자열 유효한 HTTP 메서드 body: 문자열 요청 본문 headers: 문자열 HTTP 헤더 콜백: 함수가 있는 오브젝트 | ai.xml.sax | OAuth를 사용하여 권한 부여가 있는 XML 스트림을 파싱할 수 있는 XML SAX 파서 오브젝트를 생성합니다. |
다음
ai.xml.sax
아래의 예는 다음을 사용합니다. callbacks
. 콜백은 다른 함수의 실행이 완료된 후 실행되는 함수입니다. ai.xml.sax 파서와 함께 콜백을 사용하는 경우의 이점 중 하나는 오류를 파악하고 CCDS 실행 로그에 해당 오류를 표시하여 문제를 더 쉽게 해결할 수 있다는 점입니다.- ai.xml.sax.createFromText example
- var data = { books: [], currentTag: '' }; function createSaxParser(callbacks) { var xml = '<BookStore><book category="Cooking"><title lang="en">Everyday Italian</title><author>Giada De Laurentiis</author><year>2005</year><price>$30.00</price></book><book category="Children"><title lang="en">Harry Potter</title><author>Norwegian: . French: </author><year>2015</year> <price>$50.00</price></book><book category="Sports"><title lang="en">Sports for Health</title><author>Šumbera</author><year>2016</year><price>$330.00</price></book> </BookStore>'; try { return ai.xml.sax.createFromText(xml, "UTF8", callbacks); } catch(exception) { ai.log.logError('Unable to setup sax parser', '' + exception); throw exception; } } function testConnection(context) { var parser = null; var callbacks = {}; var matched = false; callbacks.onOpenTag = function (tag) { if(tag.name === 'book') { matched = true; parser.stop(); } }; parser = createSaxParser(callbacks); parser.readToEnd(); return matched; } function importStructure(context) { var builder = context.getStructureBuilder(); var table = builder.addTable('MyNewTableFromText'); table.setDisplayName('MyNewTableFromText'); addColumn(table, 'book', 1, 'string', 100); addColumn(table, 'title', 2, 'string', 500); addColumn(table, 'author', 3, 'string', 100); addColumn(table, 'year', 4, 'string', 200); addColumn(table, 'price', 5, 'string', 1000) } function importData(context) { var rowset = context.getRowset(); rowset.setSmartParsingEnabled(true); var parser = null; var callbacks = {}; callbacks.onOpenTag = function (tag) { data.currentTag = tag.name; if(tag.name === 'book') { var book = { category: tag.attributes['category'] }; data.books.push(book); } }; callbacks.onText = function (text) { var current = data.books.length > 0 ? data.books[data.books.length-1] : null; if(data.currentTag === 'title') { current.title = text; } if(data.currentTag === 'author') { current.author = text; } if(data.currentTag === 'year') { current.year = text; } if(data.currentTag === 'price') { current.price = text; } }; callbacks.onCloseTag = function (tagname) { if(tagname === 'book') { var saving = data.books.pop(); save(rowset, saving); } }; parser = createSaxParser(callbacks); parser.readToEnd(); } function addColumn(table, columnName, order, type, length) { var newCol = table.addColumn(columnName); newCol.setDisplayName(columnName); newCol.setDisplayOrder(order); newCol.setIncludeByDefault(true); switch (type) { case 'string': newCol.setTextColumnType(length); newCol.setRemoteColumnType('string'); break; case 'datetime': newCol.setDateTimeColumnType(); newCol.setRemoteColumnType('datetime'); break; case 'float': newCol.setFloatColumnType(); newCol.setRemoteColumnType('float'); break; default: newCol.setTextColumnType(100); newCol.setRemoteColumnType('string'); } } var save = function (rowset, book) { var cells = []; cells.push(book.category); cells.push(book.title); cells.push(book.author); cells.push(book.year); cells.push(book.price); rowset.addRow(cells); };
- ai.xml.sax.createFromUrl example
- var data = { entires: [], currentTag: '' }; function createSaxParser(callbacks) { var url = 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.atom'; var method = 'GET'; var body = ``; var headers = {}; try { return ai.xml.sax.createFromUrl(url, method, body, headers, callbacks); } catch (exception) { ai.log.logError('Unable to setup sax parser', '' + exception); throw exception; } } function testConnection(context) { var parser = null; var callbacks = {}; var matched = false; callbacks.onOpenTag = function (tag) { if (tag.name === 'entry') { matched = true; parser.stop(); } }; parser = createSaxParser(callbacks); parser.readToEnd(); return matched; } function importStructure(context) { var builder = context.getStructureBuilder(); var table = builder.addTable('StandardLoaderData'); table.setDisplayName('StandardLoaderData'); addColumn(table, 'id', 0, 'string', 100); addColumn(table, 'title', 1, 'string', 500); addColumn(table, 'updated', 2, 'string', 100); addColumn(table, 'link', 3, 'string', 200); addColumn(table, 'summary', 4, 'string', 1000); addColumn(table, 'georss:point', 5, 'string', 200); addColumn(table, 'georss:elev', 6, 'string', 200); } function importData(context) { var rowset = context.getRowset(); rowset.setSmartParsingEnabled(true); var parser = null; var callbacks = {}; callbacks.onOpenTag = function (tag) { data.currentTag = tag.name; if (tag.name == 'entry') { var entry = {}; data.entires.push(entry); return; } if (tag.name == 'link') { if (tag.attributes) { var current = data.entires.length > 0 ? data.entires[data.entires.length-1] : null; if(current !== null) { current.link = tag.attributes["href"]; } } } }; callbacks.onText = function (text) { var current = data.entires.length > 0 ? data.entires[data.entires.length-1] : null; if(current === null) { return; } switch (data.currentTag) { case "id": case "title": case "updated": case "summary": case "georss:point": case "georss:elev": current[data.currentTag] = text; break; } }; callbacks.onCloseTag = function (tagname) { if (tagname == 'entry') { var saving = data.entires.pop(); save(rowset, saving); } }; callbacks.onCData = function (data) { if (data.length === 0) return; if (data.currentTag == 'summary') { var current = data.entires.length > 0 ? data.entires[data.entires.length-1] : null; current.summary = data; } }; parser = createSaxParser(callbacks); parser.readToEnd(); } function addColumn(table, columnName, order, type, length) { var newCol = table.addColumn(columnName); newCol.setDisplayName(columnName); newCol.setDisplayOrder(order); newCol.setIncludeByDefault(true); switch (type) { case 'string': newCol.setTextColumnType(length); newCol.setRemoteColumnType('string'); break; case 'datetime': newCol.setDateTimeColumnType(); newCol.setRemoteColumnType('datetime'); break; case 'float': newCol.setFloatColumnType(); newCol.setRemoteColumnType('float'); break; default: newCol.setTextColumnType(100); newCol.setRemoteColumnType('string'); } } var save = function (rowset, entry) { var cells = []; cells.push(entry.id || ''); cells.push(entry.title || ''); cells.push(entry.updated || ''); cells.push(entry.link || ''); cells.push(entry.summary || ''); cells.push(entry['georss:point'] || ''); cells.push(entry['georss:elev'] || ''); rowset.addRow(cells); };
ai.xml.parser
방법 | 매개변수 | 반품 | 설명 |
|---|---|---|---|
parse( xmlStr ) |
| ai.xml.document | 유효한 XML 문서 문자열을 XML 문서로 파싱합니다. |
- 구문분석 예
- var xmlString = '<request><control><senderid>adaptiveplanning</senderid><password>Bts9DrRkeZ</password><controlid>SomeRandomThingToMatchToResponse</controlid><dtdversion>3.0</dtdversion></control><operation><authentication><login><userid>Julia</userid><companyid>companyplanningDEV</companyid><password>GhY93tYi</password></login></authentication></operation></request>'; var parser = ai.xml.createParser(); var xmlDoc = parser.parse(xmlString); /* Output: <request> <control> <senderid>adaptiveplanning</senderid> <password>Bts9DrRkeZ</password> <controlid>SomeRandomThingToMatchToResponse</controlid> <dtdversion>3.0</dtdversion> </control> <operation> <authentication> <login> <userid>Julia</userid> <companyid>companyplanningDEV</companyid> <password>GhY93tYi</password> </login> </authentication> </operation> </request> */
ai.xml.document
방법 | 매개변수 | 반품 | 설명 |
|---|---|---|---|
clone() | ai.xml.document | 이 문서의 복제본을 반환합니다. | |
getDOCTYPE() | ai.xml.docType | 문서 DOCTYPE을 가져옵니다. | |
getRootElement() | ai.xml.element | 문서의 root 요소를 가져옵니다. | |
setDOCTYPE( docType ) |
| 문서 DOCTYPE을 설정합니다. | |
setRootElement( 요소 ) |
| 문서 root 요소를 설정합니다. | |
toString() | XML 문서의 형식이 지정된 문자열 표현을 제공합니다. |
ai.xml.docType
방법 | 매개변수 | 반품 | 설명 |
|---|---|---|---|
toString() | String | 이 문서 유형 선언의 문자열 표현을 제공합니다. |
- 예:
- var doc = ai.xml.createDocument(); var docType = ai.xml.createDocType('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'); //set doc type doc.setDOCTYPE(docType); //get doc type var getdoctype=doc.getDOCTYPE(); var rootEl = ai.xml.createElement('Books'); //set root element doc.setRootElement(rootEl); //sample clone var cloned_doc=doc.clone(); //get root element var docRoot=doc.getRootElement(); //convert the xml result to a string for logging ai.log.logInfo(doc.toString()) /*Output: Cloned data: <Books /> Doc type is<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Root element is <Books /> */
ai.xml.element
방법 | 매개변수 | 반품 | 설명 |
|---|---|---|---|
addChildElement( element ) |
| child 요소를 추가합니다. | |
clone() | ai.xml.element | 이 요소의 복제본을 반환합니다. | |
getAttribute( name ) | name: 문자열 특성의 이름입니다. | ai.xml.attribute | 지정된 이름의 특성을 가져옵니다. |
getAttributeAt( index ) | index: 특성의 정수 인덱스 | ai.xml.attribute | 이 요소에 대한 특성 배열의 지정된 인덱스에서 특성을 가져옵니다. |
getAttributes() | Array<ai.xml.attribute> | 이 요소의 특성을 가져옵니다. | |
getAttributeValue( name ) |
| String | 지정된 이름의 특성 값을 가져옵니다. |
getChildElement( name ) |
| ai.xml.element | 지정된 이름을 가진 첫 번째 child 요소를 가져옵니다. |
getChildElementAt( index ) |
| ai.xml.element | child 요소 내에서 지정된 인덱스에 있는 child 요소를 가져옵니다. |
getChildElements() | 배열<ai.xml.elements> | 이 요소에 대한 모든 child 요소의 배열을 가져옵니다. | |
getChildElements( name ) |
| Array<ai.xml.element> | 지정된 이름을 가진 이 요소에 대한 child 요소의 배열을 가져옵니다. |
getCommentText() | String | 코멘트 텍스트를 가져옵니다. | |
getName() | String | 이 요소의 정규화된 이름을 가져옵니다. | |
getText() | String | 이 요소 또는 CDATA의 텍스트를 가져옵니다. | |
hasContents() | 부울 | 이 요소에 하위 콘텐츠(텍스트, CDATA 또는 child 요소)가 있는지 여부를 나타냅니다. | |
removeAllAttributes() | 이 요소에서 모든 특성을 제거합니다. | ||
removeAttribute( name ) |
| 요소 특성 배열에서 지정된 이름의 특성을 제거하고 배열을 다시 압축합니다. | |
removeChildElement( name ) |
| 지정된 이름을 가진 첫 번째 child 요소를 제거합니다. | |
removeChildElementAt( index ) |
| child 요소 내에서 지정된 인덱스에 있는 child 요소를 제거합니다. | |
removeChildElements() | 정수 | 이 요소에서 모든 child 요소를 제거하고 제거된 요소의 수를 반환합니다. | |
removeChildElements( name ) |
| 정수 | 이 요소에서 지정된 요소명의 child 요소를 모두 제거하고 제거된 요소의 수를 반환합니다. |
removeComments() | 이 요소에 직접 첨부된 모든 코멘트를 제거합니다. | ||
removeText() | 이 요소에 직접 첨부된 모든 텍스트(CDATA 섹션 포함)를 제거합니다. | ||
setAttribute( attribute) |
| 이 요소에 특성을 추가합니다. | |
setAttribute(name, value ) |
| 이 요소에 대해 지정된 이름의 특성 값을 설정합니다. | |
setCDATAText( text ) |
| child 요소를 포함하여 이 요소에서 모든 기존 콘텐츠(코멘트 제외)를 제거한 다음, 이 요소에 대한 CDATA 섹션 텍스트를 설정합니다. | |
setCommentText( text ) |
| 이 요소에 직접 첨부된 코멘트를 모두 제거한 다음, 지정된 텍스트를 사용하여 새 코멘트를 추가합니다. | |
setName( name ) |
| 이 요소의 이름을 설정합니다. | |
setText( text ) |
| child 요소를 포함하여 이 요소에서 모든 기존 콘텐츠(코멘션 제외)를 제거한 다음 요소 텍스트를 설정합니다. | |
toString() | 이 요소의 형식이 지정된 문자열 표현을 제공합니다. |
- 예
- createDocument(), createElement(name), addChildElement(name), clone(), setText(), setCommentText(text), getCommentText()의 예// create XML document var doc = ai.xml.createDocument(); // create root element var requestEl = ai.xml.createElement('request'); // create an element '<control>' var controlEl = ai.xml.createElement('control'); //create a username or id element '<senderid>' var senderIdEl = ai.xml.createElement('senderid'); //set text for the senderid element 'adaptive planning' senderIdEl.setText('adaptiveplanning'); //add <senderid> to <control> element controlEl.addChildElement(senderIdEl); //create a <password> element var passwordEl = ai.xml.createElement('password'); //set text for the password element 'pwd' passwordEl.setText('pwd'); //add <password> to <control> element controlEl.addChildElement(passwordEl); //add <control> element to the root requestEl.addChildElement(controlEl); //clone the sender id element cloneEl=senderIdEl.clone(); //add clone() element to the root element requestEl.addChildElement(cloneEl); //setCommentText requestEl.setCommentText("The above element is cloned"); //get comment text ai.log.logInfo(getCommentText()); //Log Output: The above element is cloned //set document's root doc.setRootElement(requestEl); /* Output: <request> <control> <senderid>adaptiveplanning</senderid> </control> <senderid>adaptiveplanning</senderid> <!-- The above element is cloned--> </request> */getChildElement(), getChildElementAt(), getChildElements 및 getChildElements( name )의 예// create XML document var doc = ai.xml.createDocument(); // create root element var requestEl = ai.xml.createElement('request'); // create an element '<control>' var controlEl = ai.xml.createElement('control'); //create a username or id element '<senderid>' var senderIdEl = ai.xml.createElement('senderid'); //set text for the senderid element 'adaptive planning' senderIdEl.setText('Sender id 1'); //add <senderid> to <control> element controlEl.addChildElement(senderIdEl); //create another sender id element '<senderid>' var senderIdEl2 = ai.xml.createElement('senderid'); //set text for the senderid element 'adaptive planning' senderIdEl2.setText('Sender id 2'); //add <senderid> to <control> element controlEl.addChildElement(senderIdEl2); //create a <password> element var passwordEl = ai.xml.createElement('password'); //set text for the password element 'pwd' passwordEl.setText('pwd'); //add <password> to <control> element controlEl.addChildElement(passwordEl); //add <control> element to the root requestEl.addChildElement(controlEl); //set document's root doc.setRootElement(requestEl); //getChildElement(name) var firstChildElement="First Child element of <control> is "+requestEl.getChildElement( "senderid" ).toString(); //Output: First Child element of <control> is <senderid>Sender id 1</senderid> //getChildElementAt(index) var elementIndex="Element at index 0 is"+requestEl.getChildElementAt( 0 ).toString(); /* Output: Element at index 0 is <control><senderid>Sender id 1</senderid><senderid>Sender id 2</senderid><password>pwd</password></control> */ //getChildElements() var specificChildElements="Child elements for the control element:"+controlEl.getChildElements().toString(); //Output: <senderid>Sender id 1</senderid><senderid>Sender id 2</senderid><password>pwd</password> //getChildElements(name) var childElementsControl="All child elements of control element with <senderid>: "+controlEl.getChildElements("senderid" ).toString(); //Output:All child elements of control element with <senderid>:<senderid>Sender id 1</senderid>,<senderid>Sender id 2</senderid>hasContents(), RemoveChildElement( name ), RemoveChildElementAt(index), RemoveChildElements() 및 RemoveChildElements( name )의 예// create XML document var doc = ai.xml.createDocument(); // create root element var requestEl = ai.xml.createElement('request'); // create an element '<control>' var controlEl = ai.xml.createElement('control'); //create a username or id element '<senderid>' var senderIdEl = ai.xml.createElement('senderid'); //set text for the senderid element 'adaptive planning' senderIdEl.setText('Sender id 1'); //getText() ai.log.logInfo(senderIdEl.getText()); //Sender id 1 //add <senderid> to <control> element controlEl.addChildElement(senderIdEl); //create another sender id element '<senderid>' var senderIdEl2 = ai.xml.createElement('senderid'); //set text for the senderid element 'adaptive planning' senderIdEl2.setText('Sender id 2'); //add <senderid> to <control> element controlEl.addChildElement(senderIdEl2); //create a <password> element var passwordEl = ai.xml.createElement('password'); //set text for the password element 'pwd' passwordEl.setText('pwd'); //add <password> to <control> element controlEl.addChildElement(passwordEl); //add <control> element to the root requestEl.addChildElement(controlEl); //set document's root doc.setRootElement(requestEl); //removeChildElement of <control> element - First child element removal var removeFirstChildElement=controlEl.removeChildElement( "senderid" ); /*Output: |Inital XML | After removal of the child element <request> <request> <control> <control> <senderid>Sender id 1</senderid> <senderid>Sender id 2</senderid> <senderid>Sender id 2</senderid> <password>pwd</password> <password>pwd</password> </control> <control/> </request> <request/> */ //removeChildElementAt index 0 var removeIndexChildElement=requestEl.removeChildElementAt(0); /*Output: |Initial XML | After removing the child element at index 0 <request> <request><request/> <control> <senderid>Sender id 1</senderid> <senderid>Sender id 2</senderid> <password>pwd</password> <control/> <request/> */ //removeChildElements() var removeAllChildElements= controlEl.removeChildElements(); /*Output: |Initial XML | After removing the child element at index 0 <request> <request><control/><request/> <control> <senderid>Sender id 1</senderid> <senderid>Sender id 2</senderid> <password>pwd</password> <control/> <request/> */ //removeChildElements( name ) and hasContents() if(controlEl.hasContents()){ var removeSpecificElement=controlEl.removeChildElement( "senderid" ); } /*Output: |Inital XML | After removal of the child element <request> <request> <control> <control> <senderid>Sender id 1</senderid> <password>pwd</password> <senderid>Sender id 2</senderid> </control> <password>pwd</password> </request> <control/> <request/> */
ai.xml.attribute
방법 | 매개변수 | 반품 | 설명 |
|---|---|---|---|
clone() | ai.xml.attribute | 이 특성의 복제본을 반환합니다. | |
getName() | String | 특성의 이름을 가져옵니다. | |
getValue() | String | 특성의 값을 가져옵니다. | |
setName( name ) |
| 특성의 이름을 설정합니다. | |
setValue( value ) |
| 특성의 값을 설정합니다. | |
toString() | 이 특성의 문자열 표현을 반환합니다. |
- 예:
- var tablesElement = ai.xml.createElement('Tables'); var table1Element = ai.xml.createElement('Table'); var row1=ai.xml.createElement('row'); var row2=ai.xml.createElement('row'); //Create a new arribute var attribute1 = ai.xml.createAttribute('remoteId', '248'); //Add the attribute to <table> element using setAttribute(ai.xml.attribute) table1Element.setAttribute(attribute1); //Or set the name and value of the attribute for the <row> elements using setAttribute(name,value) row1.setAttribute('age','50'); row1.setAttribute('color','white'); row2.setAttribute('age','35'); row2.setAttribute('color','blue'); //Set text for the <table> element table1Element.setText('Sample table'); //Add <table> as the child of <tables> element tablesElement.addChildElement(table1Element); table1Element.addChildElement(row1); table1Element.addChildElement(row2); /*Ouput <Tables> <Table remoteId="248"> Sample table <row age="50" /> <row age="35" /> </Table> </Tables> */ //Clone() attributes var cloned = row1.clone(); cloned.setName('cloned_row'); table1Element.addChildElement(cloned); /*Ouput <Tables> <Table remoteId="248"> Sample table <row age="50" /> <row age="35" /> <cloned_row age="50"> </Table> </Tables> */ //getAttribute( name ) ai.log.logInfo(table1Element.getAttribute("remoteid")); //Output:remoteId="248" //getAttributeAt( index ) ai.log.logInfo(row1.getAttributeAt(0).toString()); //Output: age=50 //getAttributes() ai.log.logInfo(row1.getAttributes().toString()); //Output: age="50",color="white" //getAttributeValue( name ) ai.log.logInfo(row2.getAttributeValue('color').toString()); //Output: blue //removeAttribute( name ) var removeRow1Attribute=row1.removeAttribute('age'); /*Output: |Inital XML | After removing the attribute 'age' for row1 <Tables> <Tables> <Table remoteId="248">Sample table <Table remoteId="248">Sample table <row age="50" color="white" /> <row color="white" /> <row age ="35" color="blue" /> <row age ="35" color="blue" /> <Table/> <Table/> <Tables/> <Tables/> */ //removeAllAttributes() var removeRow1Attributes=row1.removeAllAttributes(); /*Output: |Inital XML | After removing the attribute 'age' for row1 <Tables> <Tables> <Table remoteId="248">Sample table <Table remoteId="248">Sample table <row age="50" color="white" /> <row/> <row age ="35" color="blue" /> <row age ="35" color="blue" /> <Table/> <Table/> <Tables/> <Tables/> */
AWS S3를 사용하여 XML 출력 로그 조회
ai.log 메서드를 사용하여 결과를 기록하려면 먼저 샘플 XML을 구문분석해야 합니다. 원시 XML 샘플을 조회하려면 다음을 사용하여 파일을 문자열로 변환합니다.
toString()
함수를 실행하고 AWS S3 버킷에서 파일을 조회합니다. 아래 예를 사용하여 XML 결과를 생성하고 조회하기 위해 AWS S3 인스턴스에 연결합니다. 버킷 이름, 키, 액세스 키, 비밀키 및 지역 이름이 필요합니다. 자세한 내용 및 예시 코드는ai.awss3를 참조하십시오.
- 예:
- function testConnection(context) { var bucketName = 'xxx'; var key = 'newfile.xml'; var awsAccessKey = 'xxx'; var awsSecretKey = 'xxx'; var region = 'xxx' var doc = ai.xml.createDocument(); var docType = ai.xml.createDocType('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'); //set doc type doc.setDOCTYPE(docType); //get doc type var getdocType="Doc type is"+doc.getDOCTYPE().toString(); var rootEl = ai.xml.createElement('Books'); //set root element doc.setRootElement(rootEl); //get root element var getroot="Root element is "+doc.getRootElement().toString(); //Combine the Doc type and the root element sentences to form a string var result = getdocType+"\n"+getroot; //send the string to a file on aws ai.awss3.putFile(bucketName, key, result.toString(), region, awsAccessKey, awsSecretKey); return true; } /* Output: Doc type is<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Root element is <Books /> */