topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday November 8, 2024, 8:20 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: How to extract tree hierarchy in xml?  (Read 5998 times)

kalos

  • Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 1,824
    • View Profile
    • Donate to Member
How to extract tree hierarchy in xml?
« on: July 25, 2018, 08:09 AM »
Hello!

You know that xml files are hierarchical, ie there is a top level attribute, then sub-attributes are indented and so on.

How can I copy the hierarchy, ie the upper level attributes of a selected attribute/line?

For example:

<a>
     <1>
     <2>
           <x1>
           <x2>

I want to select x2 and copy the hierarchy of it, ie the upper level attributes that x2 belongs to:
<a>
     <2>


Any idea?

Thanks!

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: How to extract tree hierarchy in xml?
« Reply #1 on: July 25, 2018, 12:49 PM »
If this is something you're going to need often, you can look into XSLT - it lets you transform XML files in pretty flexibly ways.

It's pretty clunky to work with, though, so if you need a quick solution for a specific problem, there's probably easier ways.
- carpe noctem

kalos

  • Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 1,824
    • View Profile
    • Donate to Member
Re: How to extract tree hierarchy in xml?
« Reply #2 on: July 30, 2018, 09:55 AM »
Thanks, as for now, is there an XML reader that can extract the hierarchy tree of a specific line?

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: How to extract tree hierarchy in xml?
« Reply #3 on: July 30, 2018, 12:41 PM »
is there an XML reader that can extract the hierarchy tree of a specific line?
I use Notepad++ with plug-ins "XML Tools" and "Npp XML Treeview". The XML Tools plug-in has a nice and quick formatting feature (Ctrl-Alt-Shift-B), XPath expression evaluation and it shows the path to the current node when pressing Ctrl-Alt-Shift-P. With the treeview plug-in you can see the structure of the xml nodes (but not the attributes), and quickly select a node.

If that doesn't suffice, there's always XML Copy Editor, an open source specialized XML editor with a lot of features, including XSLT and XPath support. I hardly use it but it does offer some features not easily available in Notepad++ with it's plug-ins.

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,190
    • View Profile
    • Donate to Member
Re: How to extract tree hierarchy in xml?
« Reply #4 on: July 30, 2018, 02:04 PM »
You could also use an online one.

https://codebeautify.org/xmlviewer

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: How to extract tree hierarchy in xml?
« Reply #5 on: July 30, 2018, 03:01 PM »
And if the OP feels really adventurous, he could try to use PowerShell, it seems to handle XML quite nicely, like I found in this ServerFault item, but it helps if you speak XPath, I guess...

You could also use an online one.

https://codebeautify.org/xmlviewer
It doesn't have much of the features the OP asked, though, and I'm a bit worried how/if it will handle a large xml file...

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,190
    • View Profile
    • Donate to Member
Re: How to extract tree hierarchy in xml?
« Reply #6 on: July 30, 2018, 07:53 PM »
I've used their JSON viewer on a large file before (7MB+) and it handled it with aplomb.  It doesn't extract the hierarchy, but it does visualize it, so he can know what to copy from the tree.  Just a suggestion.