Monday, 24 December 2018

Fetching or selecting or adding attribute value in esql IIB



How to fetch or select attribute value in esql IIB ?


Input xml:
-------------

<parent id="12345">
    <id>ABCDE</id>
</parent>

esql Code :
--------------

SET value = FIELDVALUE(InputRoot.XMLNS.parent.(XML.Element)id);
Result : value is 'ABCDE'

---To fetch attribute value

SET value = FIELDVALUE(InputRoot.XMLNS.parent.(XML.Attr)id);
Result : value is '12345'





How to set attribute value in esql IIB ?

Input XML
--------------

<Invoice>
 <Purchases>
    <Item>
      <Title Category='Computer' Form='Paperback' Edition='2'>The XML Companion</Title>
      <ISBN>0201674866</ISBN>
      <Author>Neil Bradley</Author>
      <Publisher>Addison-Wesley</Publisher>
      <PublishDate>October 1999</PublishDate>
      <UnitPrice>27.95</UnitPrice>
      <Quantity>2</Quantity>
    </Item>
 </Purchases>
</Invoice>


esql Code :
-------------

-- 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.XMLNS.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;

Result :
----------

<Data>
  <Attributes>
    <Category>Computer</Category>
    <Form>Paperback</Form>
    <Edition>2</Edition>
  </Attributes>
</Data>



Note : 

Field type constants with prefix ‘XML.' are for use with the XMLNS and XML parsers only

they do not work with the XMLNSC or MRM parsers.

--------------------------------------------------------
                            XMLNS Field Type constant
--------------------------------------------------------
Tag          ---       XML.Element
---------------------------------------------------------
Attribute  ---      XML.Attribute
                           XML.Attr
---------------------------------------------------------

No comments:

Post a Comment

Sending file as multi-part MIME over http in ACE - esql

  How to send a file over http as a multipart mime? Below are the steps to do that - 1. Make sure you have the data encryption in place for ...