Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Find an xml element by attribute

New Here ,
Jul 22, 2010 Jul 22, 2010

Hi ,

I am writing an javascript to find all <informalfigure> xml element that has no "type" attribute. When I run my script, it display an error message:

Error: Adobe InDesign cannot processXpath expression ""

my script is:

#target indesign-6.0
#include "glue code.jsx"
var myDocument = app.activeDocument;
var alltags = new Array;
var i1 = 0;

    var myXPath =  "//informalfigure[not(@type)]";
    var myRuleSet = new Array (new ProcessProduct);
    var myDoc = app.activeDocument;   
    with(myDocument) {
        try {
            var elements = xmlElements;
            __processRuleSet(elements.item(0), myRuleSet);
            }
        catch (err) {
            alert (err);
            }
        }

alert(alltags.length)

function ProcessProduct()
{
    this.name = "ProcessProduct";
    this.xpath = myXPath;
    this.apply = function(myElement, myRuleProcessor)  {
        alltags[i1++] = myElement;
        }
    return true;
    }


Can any one tell me where it is wrong.

Thanks,

Gopal

TOPICS
Scripting
3.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 22, 2010 Jul 22, 2010

Aaagh!!! XPath Limitation in ID I guess.

Your XPath statement (I guess) is not supported in ID  "//informalfigure[not(@type)]"

though you can do //informalfigure[@type]" or //informalfigure", but I can understand that you are interested only in "informalfigure" elements with no "type" attributes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 28, 2010 Jul 28, 2010

Dear PankChat

I'm having the doubt about can we use XML NameSpaces in Javascript. Is it possible?

In my XPath Statement is "ce:figure[@id]"

//======================= Start Script =======================//

#target indesign-6.0
#include "D:\\program files\\Adobe InDesign CS4\\Scripts\\XML Rules\\glue code.jsx"
var myDocument = app.activeDocument;
var alltags = new Array;
var i1 = 0;

    var myXPath =  "//ce:figure[@id]";
    var myRuleSet = new Array (new ProcessProduct);
    var myDoc = app.activeDocument;
    with(myDocument) {
        try {
            var elements = xmlElements;
            __processRuleSet(elements.item(0), myRuleSet);
            }
        catch (err) {
            alert (err);
            }
        }

alert(alltags.length)

function ProcessProduct()
{
    this.name = "ProcessProduct";
    this.xpath = myXPath;
    this.apply = function(myElement, myRuleProcessor)  {
        alltags[i1++] = myElement;
        }
    return true;
    }

//======================= End Script =======================//

OutPut though InDesign :     Error: Adobe Indesign cannot process ^1XPath expression '^2'

I checked so many ways, but I can't get the solution Please let me know your comments and suggestion...

Regards

T.R.Harihara Sudhan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 28, 2010 Jul 28, 2010

Try changing your XPath statement

    var myXPath =  "//ce:figure[@id]";

to

    var myXPath =  "//figure[@id]";

Weird, I know but will work I hope. Let me know.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 28, 2010 Jul 28, 2010

Dear Pankaj,

Many thanks for this quick mail, I already checked with what you mentioned in this blog. I got the nice answers.

But my queries and doubt regarding for this XMLNameSpace only. How to use the NameSpace in this particular area.

Please kindly check and let me know your suggestion / comments.

Regards,

T.R.Harihara Sudhan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 14, 2017 Jan 14, 2017
LATEST

Hi,

Can I also find and change attributes?

Sumit

-Sumit
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines