# XML object for Adobe InDesign

**URL:** <https://forums.creativeclouddeveloper.com/t/xml-object-for-adobe-indesign/7193>\
**Category:** InDesign\
**Created:** [November 30, 2023, 7:13pm UTC](https://forums.creativeclouddeveloper.com/t/xml-object-for-adobe-indesign/7193 "2023-11-30T19:13:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![medium\_jon](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/medium_jon/32/2371_2.png) [@medium\_jon](https://forums.creativeclouddeveloper.com/u/medium_jon)\
**Post date:** [November 30, 2023, 7:13pm UTC](https://forums.creativeclouddeveloper.com/t/xml-object-for-adobe-indesign/7193/1 "2023-11-30T19:13:25Z")

</div>

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. 🤦‍♂️

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

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

Jon

---

<div class="post-metadata">

**Author:** ![Omachi](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/omachi/32/3188_2.png) [@Omachi](https://forums.creativeclouddeveloper.com/u/Omachi)\
**Post date:** [November 30, 2023, 11:17pm UTC](https://forums.creativeclouddeveloper.com/t/xml-object-for-adobe-indesign/7193/2 "2023-11-30T23:17:41Z")

</div>

See this.

> **[DOM Parser not working in IDJS script](https://community.adobe.com/t5/indesign-discussions/dom-parser-not-working-in-idjs-script/td-p/13980355)**
>
> Hi All,   I'm developing the UXP scripts for InDesign. While reading the HTML file, we use a DOM Parser to read the HTML file.   our UXP is not supporting to read the DOM parser. Kindly any one resolve this and will appreciate.   ...

---

<div class="post-metadata">

**Author:** ![medium\_jon](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/medium_jon/32/2371_2.png) [@medium\_jon](https://forums.creativeclouddeveloper.com/u/medium_jon)\
**Post date:** [December 1, 2023, 12:06am UTC](https://forums.creativeclouddeveloper.com/t/xml-object-for-adobe-indesign/7193/3 "2023-12-01T00:06:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Roland\_Dreger](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/roland_dreger/32/3702_2.png) [@Roland\_Dreger](https://forums.creativeclouddeveloper.com/u/Roland_Dreger)\
**Post date:** [December 3, 2023, 2:25pm UTC](https://forums.creativeclouddeveloper.com/t/xml-object-for-adobe-indesign/7193/4 "2023-12-03T14:25:40Z")

</div>

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.

```auto
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

---

<div class="post-metadata">

**Author:** ![medium\_jon](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/medium_jon/32/2371_2.png) [@medium\_jon](https://forums.creativeclouddeveloper.com/u/medium_jon)\
**Post date:** [December 3, 2023, 5:05pm UTC](https://forums.creativeclouddeveloper.com/t/xml-object-for-adobe-indesign/7193/5 "2023-12-03T17:05:42Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![medium\_jon](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/medium_jon/32/2371_2.png) [@medium\_jon](https://forums.creativeclouddeveloper.com/u/medium_jon)\
**Post date:** [December 5, 2023, 6:48pm UTC](https://forums.creativeclouddeveloper.com/t/xml-object-for-adobe-indesign/7193/6 "2023-12-05T18:48:57Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![Roland\_Dreger](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/roland_dreger/32/3702_2.png) [@Roland\_Dreger](https://forums.creativeclouddeveloper.com/u/Roland_Dreger)\
**Post date:** [December 5, 2023, 11:01pm UTC](https://forums.creativeclouddeveloper.com/t/xml-object-for-adobe-indesign/7193/7 "2023-12-05T23:01:14Z")

</div>

> [@medium\_jon](#):
>
> Has anybody tried this approach:  
> [https://developer.adobe.com/indesign/uxp/resources/recipes/xml/](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, …

---

<div class="post-metadata">

**Author:** ![medium\_jon](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/medium_jon/32/2371_2.png) [@medium\_jon](https://forums.creativeclouddeveloper.com/u/medium_jon)\
**Post date:** [December 5, 2023, 11:36pm UTC](https://forums.creativeclouddeveloper.com/t/xml-object-for-adobe-indesign/7193/8 "2023-12-05T23:36:35Z")

</div>

Thanks for the explanation, @Roland_Dreger
