ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: marcosBal on August 31, 2018, 02:55:30 PM

Title: Creating an -if condition in structured tags
Post by: marcosBal on August 31, 2018, 02:55:30 PM
I want to output a structured xml file using -X -struct.

I also want to create an -if EXPR condition so that only certain files are processed.

The EXPR in the condition includes a nested XMP tag. I know how to search a top-hierarchy tag using e.g. -if "$XMP:entries =~ /text/" , but I do not know how to search a tag within XMP:Entries. I have unsuccessfully tried several variations of -if "$XMP:entries/XMP:Entry =~ /text/" .
Any ideas??

Thanks

Marcos
Title: Re: Creating an -if condition in structured tags
Post by: Phil Harvey on August 31, 2018, 09:23:02 PM
Hi Marcos,

I don't know specifically what you want to do, but you can access a specific field in a structured tag through the flattened tag.  In your example, the flattened tag name could be XMP:entriesEntry.

- Phil
Title: Re: Creating an -if condition in structured tags
Post by: marcosBal on September 04, 2018, 09:22:54 AM
Hi Phil,

That does not seem to work for me for this particular kind of file, which is a sidecar xml file (which happens to have extension .DBX). If I try

>exiftool -ext dbx -if "$XMP:entriesEntry =~ /textToSearch/" -X -struct dir/filename

exiftool tells me the file has failed the condition.

But if I write

>exiftool -ext dbx -if "$XMP:entries =~ /textToSearch/" -X -struct dir/filename

the output is correct: it has found the text in the larger path.

Could this be because the file I am searching is an xml file, not an image file? Again, the structure of the sidecar file is
<XMP:entries>
  </XMP:Entry>
     . . .
    textToSearch

Thanks!

Marcos
Title: Re: Creating an -if condition in structured tags
Post by: Phil Harvey on September 04, 2018, 04:00:25 PM
Hi Marcos,

If you use the -struct option then you won't see the flattened EntriesEntry tag.

Use this command to extract all information:

exiftool -s FILE

then use the tag name from this output in the -if condition.

- Phil
Title: Re: Creating an -if condition in structured tags
Post by: marcosBal on September 05, 2018, 11:46:32 AM
Hi, Phil,

So -if conditions that specify nested fields are incompatible with the -struct option, right?

Thanks again!!

Marcos
Title: Re: Creating an -if condition in structured tags
Post by: Phil Harvey on September 05, 2018, 08:54:11 PM
If you request -struct tags, then your -if condition must operate on the structures too.

- Phil
Title: Re: Creating an -if condition in structured tags
Post by: marcosBal on September 06, 2018, 10:47:23 AM
Hi, Phil,

That helped! Using -s -X -struct shows that the structure within XMP:entries is flattened, albeit using some {} and field names (almost as if they were attributes of <XMP:entries>) to imply structure.


XMP:entries='{Entry={. . .otherField=value, fieldToSearch=textToSearch, anotherField=value. . . }}'


So I just did the same search, but this time including the field within which I wanted to search as text:

-if "$XMP:entries =~ /fieldToSearch=textToSearch/" ,

and that works.

However, in this case it works because the text I am searching (textToSearch) is right at the beginning of fieldToSearch. Not sure how I would search text not at the beginning of fieldToSearch. Any ideas??

Thanks!!

Marcos
Title: Re: Creating an -if condition in structured tags
Post by: Phil Harvey on September 06, 2018, 11:10:09 AM
Hi Marcos,

You could do this: -if "$XMP:entries =~ /fieldToSearch=[^=]*textToSearch/"

Then there could be anything but an equals sign before the textToSearch.

- Phil
Title: Re: Creating an -if condition in structured tags
Post by: marcosBal on September 06, 2018, 12:07:43 PM
It works! Thanks, Phil!

Marcos