Copy link to clipboard
Copied
I have to read an indesign.xmlelement.But in the input XML I am having aid:pstyle and aid:cstyle tags.When i am using EvaluateXPathExpression it does not return any value.
In the XML
<table-group></table-group> when i am using rootElement.EvaluateXPathExpression("//table-group") it gives the correct output.
But when I am using <p aid:pstyle="Tx1"></p> It does not return anything. Can you please kindly suggest me to handle aid: attributes containing tags?
pstyle attribute is namespaced (aid), so you have to include that in your xpath.
A possible way is:
var doc = app.activeDocument;
var root = doc.xmlElements[0];
var elem = root.evaluateXPathExpression('//p[@*[local-name()="pstyle" and namespace-uri()="http://ns.adobe.com/AdobeInDesign/4.0/" and .="Tx1"]]');
if(elem.length==0){
alert("No elements found");
}
else{
elem = elem[0];
var xc = elem.xmlContent;
if(xc.constructor.name=="Text"){
alert(elem.contents)
}
else{
...
Can you try with Javascript to see where the issue resides? If the javascript works fine, then it means the problem is using the XPath with VB.net. Maybe some xpath expressions are not usable in VB.net or you have to tweak something to make it VB.net compliant.
Also what you can try is start using simpler xpath and add complexity little by little. There you can see where expression interpretation fails.
Cannot help more.
Copy link to clipboard
Copied
pstyle attribute is namespaced (aid), so you have to include that in your xpath.
A possible way is:
var doc = app.activeDocument;
var root = doc.xmlElements[0];
var elem = root.evaluateXPathExpression('//p[@*[local-name()="pstyle" and namespace-uri()="http://ns.adobe.com/AdobeInDesign/4.0/" and .="Tx1"]]');
if(elem.length==0){
alert("No elements found");
}
else{
elem = elem[0];
var xc = elem.xmlContent;
if(xc.constructor.name=="Text"){
alert(elem.contents)
}
else{
alert(elem);
}
}
May be simpler approaches but that one seems to work.
Loic
PS: You did not mark your question as scripting related, you would have certainly got quicker feedback if you did.
Copy link to clipboard
Copied
Hi thanks for ur reply. But when i am trying this i get Expression expected Error. I am using vb.net 2019 . Thanks once again
Copy link to clipboard
Copied
Can you try with Javascript to see where the issue resides? If the javascript works fine, then it means the problem is using the XPath with VB.net. Maybe some xpath expressions are not usable in VB.net or you have to tweak something to make it VB.net compliant.
Also what you can try is start using simpler xpath and add complexity little by little. There you can see where expression interpretation fails.
Cannot help more.
Copy link to clipboard
Copied
I added xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/" attributes in the P tags where the output not coming. Now the output comes as expected.