Copy link to clipboard
Copied
I'm using the XML class to parse an XML string. I want to insert the parsed XML into a textbox. What is the proper way to accomplish this? My hope is that InDesign automatically wraps the text using the Tags panel when using this method. Here's my code:
var myXML = new XML( '<?xml version="1.0" encoding="UTF-8"?><root><myText>Hello World</myText></root>' ); app.selection[0].placeXML( myXML ); // app.selection[0].placeXML( myXML.elements()[0] );
This generates Error 30477: Invalid value for parameter 'using' of method 'placeXML'. Expected XMLElement, but received nothing.
1 Correct answer
As far as I can tell, it is not possible to parse an XML string and import it. You must write the string to a temporary file and import that.
Copy link to clipboard
Copied
message says it all...
you can’t expect it to work if you don’t call it the right way.
go and look at dom, everything will be clearer then.
Copy link to clipboard
Copied
Hi I used the docs to get this far, but I can't see what I'm doing wrong. Looking at the XML docs​, I used the XML constructor​ to parse an xml string. Then I used the elements method​​ to get a list of elements and I grabbed the first one from the list. Then I passed the element to the TextBox placeXML method​​​. Thanks for your help.
Copy link to clipboard
Copied
Xml constructor stands for xml loaded as javascript object. PlaceXml belongs to indesign dom.
pretty certain scripting guide introduces this but if wrong i think sdk sample scripts cover it deeply.
Copy link to clipboard
Copied
As far as I can tell, it is not possible to parse an XML string and import it. You must write the string to a temporary file and import that.

