XML object for Adobe InDesign

Can someone remind me how to access the XML object in UXP for Adobe InDesign?

I recall asking about it during office hours early this year and I thought I recall it being released, but now I don’t find any info. :man_facepalming:

In ExtendScript you could do things like XML_o = new XML (xmlText_s);

and then parse it all using . access and much more.

Jon

See this.

Thanks @Omachi. That DOM parser sounds similar to the old ExtendScript XML.

I’ll give that a try if I can’t get access to some sort built-in XML.

Jon

I also asked to implement the DOMParser and document.evaluate(...) in UXP.

Maybe doScript with ScriptLanguage.JAVASCRIPT in the UXP script is another possible workaround. Depends on the use case.

const indesign = require("indesign");
const { app, ScriptLanguage, UndoModes } = indesign ;
let jsCodeString = ""; // or file
jsCodeString += "var xmlString = \"<doc><text>Content</text></doc>\";";
jsCodeString += "var xmlObj = new XML(xmlString);"
jsCodeString += "xmlObj[\'text\'][\'@id\'] = \"123\";"
jsCodeString += "xmlObj.toXMLString();"
const res = app.doScript(jsCodeString, ScriptLanguage.JAVASCRIPT, []);
console.log("Result: " + res);

Roland

1 Like

@Roland_Dreger Thanks! I am definitely going to try that out Monday morning. My first need is pretty simple and I’m sure I can do it all in one do-script.

But, yes, I’m going to need a full dom parser for some of our other XML dependent tasks.

Jon

Reporting that calling it from ExtendScript does work for this use. Thanks @Roland_Dreger

Has anybody tried this approach:
https://developer.adobe.com/indesign/uxp/resources/recipes/xml/
?

That was also something that ExtendScript provided access to, but I never tried to use it for parsing. I guess I never understood why I’d want to add the XML to Adobe InDesign itself.

In principle, this works in the same way as with ExtendScript and has not changed for years or better for decades.

There are many use cases for this: validation and/or transformation of the XML structure during import, automatic formatting of text with paragraph and character styles, for tagging text passages with metadata, …

Thanks for the explanation, @Roland_Dreger