XML 메시지에서 속성에 액세스

XML 메시지는 태그로 디리미트된 형식과 컨텐츠가 있는 일련의 요소로 이루어집니다. 많은 XML 태그는 또한 연관된 속성의 형식으로 정보를 포함합니다. 요소가 가질 수 있는 요소 값 및 모든 속성은 트리에서 이 요소의 하위로 처리됩니다.

다음 표에는 속성을 참조하는 데 사용해야 하는 상관 이름이 나열되어 있습니다.

구문 요소 상관 이름
Attribute (XML.Attribute) - (XML.attr) is also supported
송장(Invoice) 메시지 예에서 각 Item 요소 내의 Title 요소는 세 가지 속성 Category, Form 및 Edition을 가집니다. 예를 들면, 첫 번째 Title 요소에는 다음이 들어 있습니다.
<Title Category="Computer" Form="Paperback" Edition="2">The XML Companion</Title>

InputRoot.XML.Invoice.Purchases.Item[1].Title 요소는 논리적 트리 Category, Form, Edition 내에 네 개의 하위 요소와 The XML Companion인 요소 값을 가집니다.

이 요소에 대한 속성에 액세스하려는 경우 다음 ESQL을 코드화할 수 있습니다. 이 코드 추출은 입력 메시지로부터 속성을 검색하여 이를 출력 메시지의 요소로 작성합니다. 이 예에서는 요소 자체의 값을 처리하지 않습니다.

-- Set the cursor to the first XML.Attribute of the Title, note the * after 
-- (XML.Attribute) meaning any name, because the name might not be known

DECLARE cursor REFERENCE TO InputRoot.XML.Invoice.Purchases.Item[1].Title.(XML.Attribute)*;

    WHILE LASTMOVE(cursor) DO

      -- Create a field with the same name as the XML.Attribute and set its value 
      -- to the value of the XML.Attribute                                        

      SET OutputRoot.XML.Data.Attributes.{FIELDNAME(cursor)} = FIELDVALUE(cursor);

-- Move to the next sibling of the same TYPE to avoid the Title value       
-- which is not an XML.Attribute                                            

      MOVE cursor NEXTSIBLING REPEAT TYPE;
    END WHILE;

이 ESQL이 Compute 노드에 의해 처리될 때 다음 출력 메시지가 생성됩니다.

<Data>
  <Attributes>
    <Category>Computer</Category>
    <Form>Paperback</Form>
    <Edition>2</Edition>
  </Attributes>
</Data>
SELECT문을 사용할 수도 있습니다.
SET OutputRoot.XML.Data.Attributes[] = 
        (SELECT FIELDVALUE(I.Title)                           AS title,
                        FIELDVALUE(I.Title.(XML.Attribute)Category)   AS category,
                        FIELDVALUE(I.Title.(XML.Attribute)Form)       AS form,
                        FIELDVALUE(I.Title.(XML.Attribute)Edition)    AS edition 
          FROM InputRoot.XML.Invoice.Purchases.Item[] AS I);
그러면 다음 출력 메시지를 생성합니다.
<Data>
  <Attributes>
    <title>The XML Companion</title>
    <category>Computer</category>
    <form>Paperback</form>
    <edition>2</edition>
  </Attributes>
  <Attributes>
    <title>A Complete Guide to DB2 Universal Database</title>
    <category>Computer</category>
    <form>Paperback</form>
    <edition>2</edition>
  </Attributes>
  <Attributes>
    <title>JAVA 2 Developers Handbook</title>
    <category>Computer</category>
    <form>Hardcover</form>
    <edition>0</edition>
  </Attributes>
</Data>

WHILE문으로 생성된 출력 메시지와 동일한 출력 메시지를 얻도록 결과를 세분화하기 위해 WHERE문으로 SELECT문을 규정할 수 있습니다. 두 번째 예는 덜 복잡한 ESQL로 같은 결과를 작성할 수 있다는 것을 보여줍니다.

SET OutputRoot.XML.Data.Attributes[] = 
        (SELECT FIELDVALUE(I.Title.(XML.Attribute)Category)   AS category,
                        FIELDVALUE(I.Title.(XML.Attribute)Form)       AS form,
                        FIELDVALUE(I.Title.(XML.Attribute)Edition)    AS edition 
          FROM InputRoot.XML.Invoice.Purchases.Item[] AS I
          WHERE I.Title = 'The XML Companion');
그러면 다음 출력 메시지를 생성합니다.
<Data>
  <Attributes>
    <Category>Computer</Category>
    <Form>Paperback</Form>
    <Edition>2</Edition>
  </Attributes>
</Data>
관련 개념
메시지 플로우 개요
ESQL 개요
메시지 모델링
관련 태스크
메시지 플로우 설계
메시지 플로우 컨텐츠 정의
ESQL 파일 관리
관련 참조
Compute 노드
Database 노드
Filter 노드
ESQL 참조
주의사항 | 등록상표 | 다운로드 | 라이브러리 | 지원 | 피드백
Copyright IBM Corporation 1999, 2006 마지막 갱신 날짜: 2006/08/21
ac17270_