如何在Postgres中生成类似于此的XML?注册日期,性别和学习标识符将来自数据库中的查询。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://openclinica.org/ws/studySubject/v1" xmlns:bean="http://openclinica.org/ws/beans">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-27777511"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>userName</wsse:Username>
<wsse:Password>someHashedPassword/wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<v1:createRequest>
<v1:studySubject>
<!--Optional:-->
<bean:label>CBID01</bean:label>
<bean:enrollmentDate>2016-10-28</bean:enrollmentDate>
<bean:subject>
<!--Optional:-->
<bean:gender>f</bean:gender>
</bean:subject>
<bean:studyRef>
<bean:identifier>Clinical_AutoID</bean:identifier>
</bean:studyRef>
</v1:studySubject>
</v1:createRequest>
</soapenv:Body>
</soapenv:Envelope>
答案 0 :(得分:1)
我能够生成XML文件。但如果有人知道更优雅的方法,请告诉我。 PS:我删除了标签字段,因为系统会自动生成一个。
select xmlelement(name "soapenv:Envelope",
xmlattributes('http://schemas.xmlsoap.org/soap/envelope/' AS "xmlns:soapenv",
'http://openclinica.org/ws/studySubject/v1' AS "xmlns:v1",
'http://openclinica.org/ws/beans' AS "xmlns:bean"),
xmlelement(name "soapenv:Header",
xmlelement(name "wsse:Security",
xmlattributes(1 AS "soapenv:mustUnderstand",
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd' AS "xmlns:wsse"),
xmlelement(name "wsse:UsernameToken",
xmlattributes('UsernameToken-27777511' AS "wsu:Id",
'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd' AS "xmlns:wsu"),
xmlelement(name "wsse:Username", 'userName'),
xmlelement(name "wsse:Password",'someHashedPassword')))),
xmlelement(name "soapenv:Body",
xmlelement(name "v1:createRequest",
xmlelement(name "v1:studySubject",
xmlelement(name "bean:enrollmentDate", '2016-10-28'),
xmlelement(name "bean:subject",
xmlelement( name "bean:gender", 'f')),
xmlelement(name "bean:studyRef",
xmlelement(name "bean:identifier", 'Clinical_AutoID'))
)
)
)
)
)