KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Improper XPath Syntax Causes XML Element Reference to be 0's
PRODUCT: 4D | VERSION: 18 R | PLATFORM: Mac & Win
Published On: March 15, 2021

The XML DOM Commands, DOM Create XML element, DOM Find XML element, and DOM Create XML element arrays are some of the commands that utilize XPath and can be used to retrieve a reference to an element in an XML file. If the XML element reference returned by these commands are a series of zeros (ex. 00000000000000000000000000000000), it is an invalid reference and there is likely an issue with the syntax in the provided XPath pathname.

The XPath implementation prior to v18R3 allowed non-standard syntax to be used in XPath pathnames. The XPath implementation in newly created database applications from v18R3 and up will use the standard XPath syntax. For converted database applications, there will be a compatibility setting to use the standard XPath implementation or not.

Given an XML file with the following contents:

<a>
  <
b>
  <
/b>
<
/a>

Using the Standard Xpath implementation, here is an absolute path to retrieve a reference to element "b".

$xml:=DOM Parse XML source("example.xml")
$ElementRef:=DOM Find XML element($xml;"/a/b")

Here is a relative path to retrieve a reference to element "b".

$xml:=DOM Parse XML source("example.xml")
$ElementRef:=DOM Find XML element($xml;"a/b")