2

How I can generate such XML tag in Googlescript via XmlService?

<display-name xml:lang="x-default">Adam</display-name>

I have used different variants setAttribute but nothing is works.

XmlService.createElement('display-name').setAttribute('lang', 'x-default'); 
// prefix `xml:` has not added

XmlService.createElement('display-name').setAttribute('lang', 'x-default', XmlService.getNamespace('someurl')); 
// fatal error: We're sorry, a server error occurred

XmlService.createElement('display-name').setAttribute('lang', 'x-default', XmlService.getNamespace('xml', 'someurl')); 
// fatal error: Invalid argument

// but in case fake namespace - OK
XmlService.createElement('display-name').setAttribute('lang', 'x-default', XmlService.getNamespace('qqq', 'someurl')); 
// <display-name xmlns:qqq="http://example.com" qqq:lang="x-default" />
0

1 Answer 1

1

You need to use "xml:" namespace as defined here

This is available in Google Apps Script by calling:

XmlService.getXmlNamespace()

So, you can achieve what you want with the following code:

XmlService.createElement('display-name')
      .setAttribute('lang', 'x-default', XmlService.getXmlNamespace())
      .setText('Adam');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.