Copy link to clipboard
Copied
Hi,
I need to get the content of the xml attribute values. In which I need to fetch the CDATA values based on the Attribute name for that I have attached the xml document which contains the CDATA values with the attributename ("TBGUID").
As far as unique ID is concerned, you can try this simpler code :
var file = File('~/Desktop/cdata.xml');
var returnedValue = getCDATAWithID(file, "TBGUID", "SAV1149696081");
if(returnedValue.length > 0) alert (returnedValue);
else alert ("Not Found", "Not Found", true)
//==============================
function getCDATAWithID(inputXML, attribute, id){
var CDATA = [];
if(inputXML.exists == true) {
inputXML.open('r');
var text = inputXML.read();
inputXML.close();...
Copy link to clipboard
Copied
Could you try again describing what you need, I unfortunately could not understand it at all.
-Manan
Copy link to clipboard
Copied
I have fetched the content of the xml using the attribute name, but I need to get the content of the xml file which is present inside the CDATA values using an unique id (TBGUID). I have attached the code which is used to get the content using the attribute name. Please guide me on this.,,
var allCDATA = [];
var myXMLFile = File("D:/XML/Parts.xml");
myXMLFile.open('r');
var allElements = new XML(myXMLFile.read());
myXMLFile.close();
var allFeatureElements = allElements.xpath("//features");
for(var n = 0; n < allFeatureElements.length(); n++){
if(allFeatureElements.children().length() > 0){
getChildData(allFeatureElements);
}
}
function getChildData(nodeData){
for(var c = 0; c < nodeData.children().length(); c++){
if(nodeData.children()[c].toXMLString().toString().indexOf("<![CDATA[") == 0){
alert(nodeData.children()[c].toString());
allCDATA.push(nodeData.children()[c].toString());
}
if(nodeData.children()[c].children().length() > 0){
getChildData(nodeData.children()[c]);
}
}
}
alert(allCDATA);
Copy link to clipboard
Copied
It looks like this question has already been asked in past & resolved as well.
Here is the link : Fetching xml contents from INDD
Here is the code snippet :
var allCDATA = [];
var myXMLFile = File("C:/Users/r.sunil/Desktop/TestingCDATA/Test.xml");
myXMLFile.open('r');
var allElements = new XML(myXMLFile.read());
myXMLFile.close();
var allFeatureElements = allElements.xpath("//feature");
for(var n = 0; n < allFeatureElements.length(); n++){
if(allFeatureElements.children().length() > 0){
getChildData(allFeatureElements);
}
}
//===================
function getChildData(nodeData){
for(var c = 0; c < nodeData.children().length(); c++){
if(nodeData.children()[c].toXMLString().toString().indexOf("<![CDATA[") == 0){
alert(nodeData.children()[c].toString());
allCDATA.push(nodeData.children()[c].toString());
}
if(nodeData.children()[c].children().length() > 0){
getChildData(nodeData.children()[c]);
}
}
}
alert(allCDATA);
Best
Sunil
Copy link to clipboard
Copied
As far as unique ID is concerned, you can try this simpler code :
var file = File('~/Desktop/cdata.xml');
var returnedValue = getCDATAWithID(file, "TBGUID", "SAV1149696081");
if(returnedValue.length > 0) alert (returnedValue);
else alert ("Not Found", "Not Found", true)
//==============================
function getCDATAWithID(inputXML, attribute, id){
var CDATA = [];
if(inputXML.exists == true) {
inputXML.open('r');
var text = inputXML.read();
inputXML.close();
var content = new XML(text);
var elements = content.xpath("//CDATA");
for(var n = 0; n < elements.length(); n++){
if(elements[n].parent()["@"+attribute].toString() == id){
CDATA.push(elements[n].toString());
}
}
}
return CDATA;
}
Best
Sunil
Copy link to clipboard
Copied
Is it working for you?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now