XPATH formatting question

Post Reply
mclarke
Member
Posts: 54
Joined: Thu Feb 28, 2013 5:29 pm
Location: Syracuse, NY

XPATH formatting question

Post by mclarke »

So, I have an email that is sent after a preflight that has the report attached and is sent to specific people. I wanted to include some of the preflight data in the body of the email. I have it mostly like I want it, but I'm stuck on a formatting issue.

I want to return all warnings, which I grab with the following:

[Metadata.Text:Path="//PreflightResultEntry[@level='warning']",Dataset="Log",Model="XML"]

It works, but all the warnings are strung together in one long string as follows:

Graphic element lies completely outside trim box (8x on page 1)Graphic element lies completely outside %BoxType%3108trim boxCheck

Is there any way to add a line feed/carriage return after each instance? I also wouldn't mind getting rid of the Box Type variable data, but that's not as important.
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

Re: XPATH formatting question

Post by cstevens »

The structure of your XPath is a little odd. Are you missing the Root XML node in your XPath or does the XML look like this:

Code: Select all

<PreflightResultEntry level='warning'>Graphic element lies completely outside trim box (8x on page 1)Graphic element lies completely outside %BoxType%3108trim boxCheck</PreflightResultEntry>
I assumed you were missing the root node in you XPath and that there are mulple nodes (one for each message), but Switch wouldn't let me create a path that matched multiple nodes in the path builder. I had to do something like this:

Code: Select all

[Metadata.Text:Path="//PreflightResult/PerflightResultEntry[@level='warning'][1]",Dataset="Xml",Model="XML"]
[Metadata.Text:Path="//PreflightResult/PerflightResultEntry[@level='warning'][2]",Dataset="Xml",Model="XML"]
[Metadata.Text:Path="//PreflightResult/PerflightResultEntry[@level='warning'][3]",Dataset="Xml",Model="XML"]
If you knew you were never going to get more than "N" messages inside an XML file then this might work, but if you get more messages than you have lines like this then you'll lose data (4 in this example).

If your XML looks like the top, then maybe you can do a replace, but you would need some kind of delimiter to key off of and I don't see anything in your sample.
mclarke
Member
Posts: 54
Joined: Thu Feb 28, 2013 5:29 pm
Location: Syracuse, NY

Re: XPATH formatting question

Post by mclarke »

I'm using a global search of the XML, since I am not sure how many warnings will come up. I found that trying to map the specific paths gave unreliable results, since the data could change and then the paths didn't match anymore. According to w3schools XPATH tutorial, the syntax is good.

"// Selects nodes in the document from the current node that match the selection no matter where they are"

Also, it does return the results I am looking for, just not in a format that is linguistically correct.

Here's a sample of the email that goes out with the report:


J1101644-01 contains CMY/has invalid bleed settings. Please locate the file in the repository and fix it.

The number of pages in the file: 1

The number of separations: 1

The colors in the job are PANTONE 276 C

WARNINGS:
Graphic element lies completely outside trim box (8x on page 1)Graphic element lies completely outside %BoxType%3108trim boxCheck

Originated in the PDFs - Envelope folder.



The bold line is the formatting I am trying to fix. I can post the entire text of the body of the email template, with the variables, if necessary.
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

Re: XPATH formatting question

Post by cstevens »

This might be a limitation with Switch's implementation for variables. With the scripting module you can easily return multiple nodes found by an XPath and then loop through them to do formatting or whatever else, but in the variable GUI I was getting warnings that paths selecting multiple nodes weren't valid.

Seeing the full XML would help, but I'm not sure you can do what you're trying to do without scripting.
mclarke
Member
Posts: 54
Joined: Thu Feb 28, 2013 5:29 pm
Location: Syracuse, NY

Re: XPATH formatting question

Post by mclarke »

cstevens wrote:Seeing the full XML would help, but I'm not sure you can do what you're trying to do without scripting.
That's the same realization I was coming to as well. We have the scripting module as well, I just have to get more confident in script writing.
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

Re: XPATH formatting question

Post by cstevens »

Basically you need to open the XML file as a document, then use an evaluation function to return the nodes:

Something like this:

Code: Select all

var inXML = new Document(job.getPath());
var nodeList = inXML.evalToNodes("//PreflightResultEntry[@level='warning']", null);
for (var i=0; i<nodeList.length; i++{
	//write to your email body or something here...
	s.log(1, nodeList.at(i).toString());
}
That's just a guess without seeing the full XML structure though.
mclarke
Member
Posts: 54
Joined: Thu Feb 28, 2013 5:29 pm
Location: Syracuse, NY

Re: XPATH formatting question

Post by mclarke »

Thanks for the sample code. I'll play with it and see what I can get to work.

Thanks again!
eschlarb
Newbie
Posts: 1
Joined: Thu May 18, 2023 5:54 pm

Re: XPATH formatting question

Post by eschlarb »

This is an old thread, but I was trying to solve the same problem and found I could use a <br> as a separator and it returned my results on individual lines - I made my xpath expression little differently, but i think we were trying to solve the same problem... I too wanted to return the results of warnings from my preflight report, and it worked like a charm..

[Metadata.TextIndexed:Dataset="preflight",Model="XML",Path="//PreflightReport/Warnings/PreflightReportItem/Message",Separator="<br>"]

Just wanted to leave it here in case someone else was trying to solve the same problem - this thread was the closest I could find to what I was looking for... (and it will probably be me looking for it later when I forget, LOL)
Arsen
Newbie
Posts: 5
Joined: Fri Apr 10, 2020 11:08 pm

Re: XPATH formatting question

Post by Arsen »

eschlarb wrote: Thu May 25, 2023 12:33 am This is an old thread, but I was trying to solve the same problem and found I could use a <br> as a separator and it returned my results on individual lines - I made my xpath expression little differently, but i think we were trying to solve the same problem... I too wanted to return the results of warnings from my preflight report, and it worked like a charm..

[Metadata.TextIndexed:Dataset="preflight",Model="XML",Path="//PreflightReport/Warnings/PreflightReportItem/Message",Separator="<br>"]

Just wanted to leave it here in case someone else was trying to solve the same problem - this thread was the closest I could find to what I was looking for... (and it will probably be me looking for it later when I forget, LOL)
Nice solution, but for the indexed data only. I am struggling with unknown amount of nodes in dataset and expression scripting doesn't help.
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: XPATH formatting question

Post by freddyp »

It is not "Nice solution, but ...", it is "Nice solution!". Period. Using TextIndexed is the way you handle an unknown number of nodes. You can use <br> as a separator as suggested, or you could use <li> as a prefix and </li> as a postfix, and when you enclose this in the mail template with <ul> </ul> you get an unordered list (bullet points) or <ol> </ol> and then you get numbers.

It was one of the topics of this monthly session: https://learning.enfocus.com/course/view.php?id=427
Post Reply