Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

JSX Parse XML String & Place Into Textbox

Explorer ,
Jan 07, 2018 Jan 07, 2018

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.

TOPICS
Scripting
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jan 10, 2018 Jan 10, 2018

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.

Translate
People's Champ ,
Jan 07, 2018 Jan 07, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 07, 2018 Jan 07, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 07, 2018 Jan 07, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 10, 2018 Jan 10, 2018
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines