Home Search

DriveWorks Pro 21
SppXPathSetAttributeValue

Send Feedback

SppXPathSetAttributeValue

Returns an XML formatted object for either a new or existing attribute value. If the attribute does not exist the function will add the new attribute and value into the specified location.

Syntax

SppXPathSetAttributeValue([XML],[Path],[Attribute Name],[New Value])

Where:

XML is an XML object such as that returned value from SppXMLFromString or SppXMLLoad, or XML as a text string.

Path is the path to the parent element, in the XML, whose values are to be set. The path needs to be separated with a back slash (\) for example Quote\Items. For multiple elements of the same name use [number] to determine which element the attribute is added to. Path is case sensitive.

Attribute Name is the name of the attribute to be edited, if the attribute does not exist it will be created with the new value.

New Value is the new value for the specified attribute.

Example

RuleResultMeaning
SppXPathSetAttributeValue(DWVariableXML,"CustomerInformation\Entry[2]\Details","Phone","0123456789")See Example Data and Example Result BelowThis will add a new attribute and value to the XML.
SppXPathSetAttributeValue(DWVariableXML,"CustomerInformation\Entry[2]\Website","www.nutsandboltsbrewing.co.uk")See Example Data and Example Result BelowThis will update an existing attributes value to the XML.

Example Data As An Array

Set of Customers information stored as an XML file brought into DriveWorks as an Array.

{"<CustomerInformation>
    <Entry>
      <Customer>Smith Garage</Customer>
      <Details Website=""www.fixmycar.co.uk"" />
    </Entry>
    <Entry>
      <Customer>Nuts and Bolts Brewing Co</Customer>
      <Details Website=""nutsandboltsbrews.co.uk"" />
    </Entry>
    <Entry>
      <Customer>FlowersBuckets</Customer>
      <Details Website=""FlowerBucket.co.uk"" />
    </Entry>
  </CustomerInformation>"}
        

Example Result (New Attribute and Value)

Result of adding a phone attribute to the second customer entry in the XML document.

{"<CustomerInformation>
    <Entry>
      <Customer>Smith Garage</Customer>
      <Details Website=""www.fixmycar.co.uk"" />
    </Entry>
    <Entry>
      <Customer>Nuts and Bolts Brewing Co</Customer>
      <Details Website=""nutsandboltsbrews.co.uk"" Phone=""0123456789"" />
    </Entry>
    <Entry>
      <Customer>FlowersBuckets</Customer>
      <Details Website=""FlowerBucket.co.uk"" />
    </Entry>
  </CustomerInformation>"}
        

Example Result (Existing Attribute)

Result of setting the existing website attribute to the second customer entry in the XML document.

{"<CustomerInformation>
    <Entry>
      <Customer>Smith Garage</Customer>
      <Details Website=""www.fixmycar.co.uk"" />
    </Entry>
    <Entry>
      <Customer>Nuts and Bolts Brewing Co</Customer>
      <Details Website=""www.nutsandboltsbrewing.co.uk"" />
    </Entry>
    <Entry>
      <Customer>FlowersBuckets</Customer>
      <Details Website=""FlowerBucket.co.uk"" />
    </Entry>
  </CustomerInformation>"}