In VanillaSoft, when working with XML posts that have complex structures, XPath syntax can be used to accurately extract the information you need from multiple levels of nodes.
Example 1: Extracting Contact Information
Consider the following XML structure:
<Application>
<Contact>
<FirstName>Test</FirstName>
<LastName>Tester</LastName>
</Contact>
<Info>
<FirstName>Test</FirstName>
<LastName>Tester</LastName>
</Info>
</Application>
In this example, there are two nodes containing first and last names. To specifically grab the contact's first and last names, you can use the following XPath paths as the incoming field names in VanillaSoft:
- First Name:
//Application/Contact/FirstName
- Last Name:
//Application/Contact/LastName
Example 2: Extracting Phone Number Information
Consider another XML structure:
<Contact>
<PhoneNumbers>
<PhoneNumber>
<PhoneNumberValue>3030000000</PhoneNumberValue>
<PhoneNumberType>Home</PhoneNumberType>
</PhoneNumber>
<PhoneNumber>
<PhoneNumberValue>3030000000</PhoneNumberValue>
<PhoneNumberType>Mobile</PhoneNumberType>
</PhoneNumber>
</PhoneNumbers>
</Contact>
In this example, there are multiple instances of "PhoneNumberValue." To grab the home phone number, you need to look for an instance where "PhoneNumberType" has "Home" in it. Here is the appropriate XPath syntax:
- Home Phone Number:
//Contact/PhoneNumbers/PhoneNumber[PhoneNumberType = "Home"]/PhoneNumberValue
By using these XPath expressions, you can effectively map and extract specific pieces of information from complex XML structures in VanillaSoft.