Print the SelfClosing tag in xml if there is no value in html form



I am able to collect the data from html form and creating a file as xml using java script by using following template. My problem is if the user not given any value in html form the xml should print that tag as selfclosing tag.



var template = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<Book>',
'<Version><?Version?></Version>',
'<Author><?Author?></Author>',
'<Page><?Page?></Page>',
'<Title><?Title?></Title>',
'<Book>'
]


my xml is printing like this



<Book>
<Version>1</Version>
<Author>james</Author>
<Page></Page>
<Title>textbook</Title>
<Book>


But i want to print like this if there is no value



<Book>
<Version>1</Version>
<Author>james</Author>
<Page/>
<Title>textbook</Title>
<Book>

No comments:

Post a Comment