cancel
Showing results for 
Search instead for 
Did you mean: 

Difference between element and attributes while creating data types

Former Member
0 Kudos

Hi Gurus,

Please provide me the difference between element and attribute.

It would be great,if I can get some example with exact usage.

Regards,

MohanRaj

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Mohan,

Elements contains information as an independent field, while attributes are those which contains data about that element means its meta data.

For eg: If ABC is a Node and it contain Field Name then Field Name is its element and at the same level If ABC have color, size, etc like fields then they are attributes which are common for all elements.

Rewards if found helpful.

BR, Kasturika Phukan

Answers (6)

Answers (6)

Former Member
0 Kudos
Former Member
0 Kudos

Hi,

Element is everything from (including) the element's start tag to (including) the element's end tag.

An element can contain other elements, simple text or a mixture of both. Elements can also have attributes.

Attributes often provide information that is not a part of the data. In the example below, the file type is irrelevant to the data, but important to the software that wants to manipulate the element.

In case you use the JDBC Adapter, for example. The muster XML-SQL from help.sap.com use attribute action to describe what kind of action should be performed, but action does not belongs to Payload, for example the content you want to insert into one table, does NOT contain action.

<root>

<StatementName1>

<dbTableName action=”UPDATE” | “UPDATE_INSERT”>

<table>realDbTableName</table>

<access>

<col1>val1</col1>

<col2>val2new</col2>

</access>

<key1>

<col2>val2old</col2>

<col4>val4</col4>

</key1>

<key2>

<col2>val2old2</col2>

</key2>

</dbTableName>

</StatementName1>

regards,

Hai

former_member267355
Active Participant
0 Kudos
Former Member
0 Kudos

Hi Mohan,

Elements and Attributes

You create complex data types using elements and attributes in the XSD editor:

Node Type

Use

Example Instance

Element

Create structured data types. Elements that have a type cannot contain subelements.

<myElem>

<f1> Value of f1 </f1>

<f2> Value of f2 </f2>

</myElem>

Attribute

Add attributes to elements. Attributes cannot usually have subnodes.

<myElem myAttr="AttributeValue">

Element Value

</myElem>

You can flag an attribute as optional or required in the Occurrence column. These values mean the same for elements with an occurrence of 0..1 or 1. The only difference between elements and attributes is that attributes cannot have subnodes and that the same attribute cannot be used more than once in an element.

Regards,

Phani

Reward points if Helpful

Former Member
0 Kudos

Well, attribute is only an attribute of element's entity. You can have just element w/o attribute, but can't have attribute w/o element.

See some pages about XML.

Peter

Former Member
0 Kudos

Hi Mohan!

This is a philosophycal question - attributes vs. elements. Technically it will work if you do in anyhow. The difference is only logical.

you can create a DT like

<person>

<name></name>

<age></name>

</person>

but also like

<person name="myname" age="myage"/>

so, depends just on your opinion, what you like more. The truth is, it is a bit easier to process attributes in XSLT and in some programming languages. But as I said, depends only on you.

Peter