Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: XML element hierarchy in TJvSimpleXML



Permlink Replies: 3 - Last Post: Mar 8, 2017 11:32 AM Last Post By: Remy Lebeau (Te...
mohamed alayadi

Posts: 17
Registered: 8/26/02
XML element hierarchy in TJvSimpleXML
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 7, 2017 11:48 PM
I use TJvSimpleXML to read information from an XML file, i have the following question :

Is there a way in TJvSimpleXML to know the complete hierarcgy name for an
XML element in TJvSimpleXML?
For example for the element "transfer" whose hierarchy is
"bookings"/"transfers"/"transfer" to get the whole name of the hierarchy,
the TJvSimpleXML XML element has only the parent property which in this
case will be "transfers" but it is insufficient as information for the
whole hierarchy.
Thanks in advance for any help..
Robert Triest

Posts: 687
Registered: 3/24/05
Re: XML element hierarchy in TJvSimpleXML
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 8, 2017 2:40 AM   in response to: mohamed alayadi in response to: mohamed alayadi
For example for the element "transfer" whose hierarchy is
"bookings"/"transfers"/"transfer" to get the whole name of the hierarchy,
the TJvSimpleXML XML element has only the parent property which in this
case will be "transfers" but it is insufficient as information for the
whole hierarchy.

You can't ask the parent of the "Transfers" property?
You iterate through the tree by asking every time what the parent of the current property is until it's empty/nil
Bernd Maierhofer

Posts: 161
Registered: 9/27/99
Re: XML element hierarchy in TJvSimpleXML
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 8, 2017 3:19 AM   in response to: mohamed alayadi in response to: mohamed alayadi
mohamed alayadi wrote:

I use TJvSimpleXML to read information from an XML file, i have the
following question :

Is there a way in TJvSimpleXML to know the complete hierarcgy name
for an XML element in TJvSimpleXML?
For example for the element "transfer" whose hierarchy is
"bookings"/"transfers"/"transfer" to get the whole name of the
hierarchy, the TJvSimpleXML XML element has only the parent property
which in this case will be "transfers" but it is insufficient as
information for the whole hierarchy.
Thanks in advance for any help..

Not easily.

Have alook at the OnParse - event, it should give you the elemnts, you
need to assemble the path.

HTH Bernd

--
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: XML element hierarchy in TJvSimpleXML
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 8, 2017 11:32 AM   in response to: mohamed alayadi in response to: mohamed alayadi
mohamed wrote:

Is there a way in TJvSimpleXML to know the complete hierarcgy
name for an XML element in TJvSimpleXML?

You have to walk the tree manually, eg:

function GetElementPath(Element: TJclSimpleXMLElem): string;
begin
  Result := Element.FullName;
  Element := Element.Parent;
  while Element <> nil do
  begin
    Result := Element.FullName + '/' + Result;
    Element := Element.Parent;
  end;
end;


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02