+ Reply to Thread
Results 1 to 2 of 2

Thread: All tags in XML or HTML files

 
  1. #1
    Contributing User
    Join Date
    May 2011
    Posts
    166
    Rep Power
    201

    Default All tags in XML or HTML files

    Hi there

    A nifty way of finding which tags are being used in a file (specially useful for XML files, where the tags can be anything) is using "grep" to get the tags, sort them (with "sort", what else?) and removing duplicates with "uniq":

    Code:
    pabloa:~$ grep -ohe "<[^/][^> ]*[ |>]" *.xml |sort|uniq 
    <city>
    <country>
    <description 
    <language>
    <metadata 
    <title>
    <topic>
    <value>
    <?xml 
    <year>
    It's so useful that I'm going to do an alias for it. Here we are using a few very nice features of the "grep" command:

    • -o: output only the matching bit instead of the whole line
    • -h: don't output the file name where the pattern was found
    • -e: use a regular expression (it seems that this has to be the last flag of the three, otherwise it malfunctions)

    The pattern used ("<[^/][^> ]*[ |>]") can be explained in words like this: "anything starting with a '<', followed by any character different than '/' (so we avoid closing tags), followed by anything which is not a space or a '>', up to (and including) a space or a '>'"

    Improve at your leisure and enjoy at your pleasure!

    Cheers.
    P.

  2. #2
    Registered User
    Join Date
    Jul 2007
    Posts
    12
    Rep Power
    216

    Default Re: All tags in XML or HTML files

    Pabloa,

    Very neat script indeed! Thank you for sharing! XML massaging is unavoidable this days when doing software localization in order to make the CAT Tools to properly digest the wide variety of structures presented by XML. I will try to share my scripts too.

    Best wishes,
    James

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Meta tags en HTML
    By Maximiliano in forum Spanish Language Topics
    Replies: 3
    Last Post: 10-31-2016, 08:28 PM
  2. Tags en Illustrator
    By antonellas in forum Spanish Desktop Publishing
    Replies: 1
    Last Post: 05-22-2013, 04:05 PM
  3. Tags en Indesign
    By tamaramf in forum Spanish Desktop Publishing
    Replies: 3
    Last Post: 11-13-2012, 12:47 PM
  4. HTML entities in XML files
    By pabloa in forum Other Software
    Replies: 0
    Last Post: 06-29-2011, 09:52 AM
  5. Replies: 1
    Last Post: 02-12-2007, 03:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •