Skip to main content
XML - Attributes Overview
Micah A. Parker avatar
Written by Micah A. Parker
Updated over a month ago

Product: Flat-Files (XML)


Attributes are tags located within a particular XML Element next proceeding after the name of the element itself. Attributes, allow for additional information (sometimes referred to as Metadata) to be contained and organized within the element itself rather than being placed as separate child element.

Attributes are often used for small-pieces of data, that may or may-not appear to help identify or tag a particular node with some modifier that helps represent the XML Element without adjusting its structure.

Attributes often act as useful tags


Sample XML


Below is an example of a Warehouse Shipping Order (940) that has been generated with Attributes. Each attribute has been highlighted below.

Example - 940 Warehouse Shipping Order

<WarehouseShippingOrder orderNumber="123456" orderDate="2024-10-16" warehouseID="WH123">

<Header>

<OrderNumber priority="high">123456</OrderNumber>

<OrderDate format="YYYY-MM-DD">2024-10-16</OrderDate>

<WarehouseID region="North">WH123</WarehouseID>

</Header>

<Shipment>

<ShipTo contactType="residential">

<Name>John Doe</Name>

<Address type="street">123 Main St</Address>

<City>New York</City>

<State>NY</State>

<PostalCode>10001</PostalCode>

</ShipTo>

<ShipFrom contactType="business">

<Name>ACME Warehouse</Name>

<Address type="street">456 Warehouse Blvd</Address>

<City>Los Angeles</City>

<State>CA</State>

<PostalCode>90001</PostalCode>

</ShipFrom>

</Shipment>

<Items>

<Item itemType="standard" itemStatus="inStock">

<ItemID>ABC123</ItemID>

<Description>Widget A</Description>

<Quantity unit="EA">10</Quantity>

<UnitOfMeasure>EA</UnitOfMeasure>

</Item>

<Item itemType="custom" itemStatus="backOrder">

<ItemID>XYZ789</ItemID>

<Description>Widget B</Description>

<Quantity unit="EA">5</Quantity>

<UnitOfMeasure>EA</UnitOfMeasure>

</Item>

</Items>

</WarehouseShippingOrder>


Attributes


An XML Attribute is simply just another way to define data. There is no hard-rule on whether to use an XML Attribute or to use a Child Element to define the information. However they do often get highlighted differently in Text-Editors that can help breakup information.

Attributes are defined in the pattern of name="value". The name of the attribute will be followed by an equal sign, and then the value of that attribute surrounded by quotes, regardless if the value is text, a true/false (boolean), or a number.

Rules

  • Attributes values must always be surrounded in quotes

  • Single or Double quotes can be used

  • Multiple attributes can be stored within an XML Tag

  • Must be stored in the starting tag

  • Cannot have spaces within the name of the attribute

    • the values within the quotes can however

EDI Usages

Some common usages for attributes are most often for tagging things such as types, ids, and metadata that help identify a particular piece of data based on a code or a list-type. For example identifying whether a line item is an Inventory Item or a type of Charge.

rev 10/16/2024

Did this answer your question?