I am building the xml format.
I want to do something like this:
<ValidationRequest>
<Username>[email protected]</Username>
<Password>XBR!t6YMeJbmsjqV</Password>
<Email>[email protected]</Email>
<Email>[email protected]</Email>
<Email>[email protected]</Email>
</ValidationRequest>
Now I can append all email into ValidationRequest. But I got the wrong format.
This is my code:
#!/usr/bin/python
import lxml.etree
import lxml.builder
email = ['[email protected]','[email protected]','[email protected]']
E = lxml.builder.ElementMaker()
ValidationRequest = E.ValidationRequest
Username = E.Username
Password = E.Password
Email = E.Email
op = []
for a in email:
GG = Email(a)
op.append(lxml.etree.tostring(GG, pretty_print=True))
print (lxml.etree.tostring(GG, pretty_print=True))
print(op)
ed = ''.join(map(str, op))
print(ed)
the_doc = ValidationRequest(
Username('admin'),
Password('XBR'),
ed
)
print (lxml.etree.tostring(the_doc, pretty_print=True))
The response:
b'<Email>[email protected]</Email>\n'
b'<Email>[email protected]</Email>\n'
b'<Email>[email protected]</Email>\n'
[b'<Email>[email protected]</Email>\n', b'<Email>[email protected]</Email>\n', b'<Email>[email protected]</Email>\n']
b'<Email>[email protected]</Email>\n'b'<Email>[email protected]</Email>\n'b'<Email>[email protected]</Email>\n'
b"<ValidationRequest><Username>admin</Username><Password>XBR</Password>b'<Email>[email protected]</Email>\\n'b'<Email>[email protected]</Email>\\n'b'<Email>[email protected]</Email>\\n'</ValidationRequest>\n"
How can I keep <Email></Email> and post to ValidationRequest?