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
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
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
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
Hi, Phil,
So -if conditions that specify nested fields are incompatible with the -struct option, right?
Thanks again!!
Marcos
If you request -struct tags, then your -if condition must operate on the structures too.
- Phil
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
Hi Marcos,
You could do this: -if "$XMP:entries =~ /fieldToSearch=[^=]*textToSearch/"
Then there could be anything but an equals sign before the textToSearch.
- Phil
It works! Thanks, Phil!
Marcos