我想创建一个XML,它将发送一个请求到第三方站点来创建会议参加者。如何在XML中控制名称空间前缀?
的文档是:https://developer.cisco.com/media/webex-xml-api/121CreateMeetingAttendee.html
给出有实例显示请求XML应该在这个格式:
<?xml version="1.0"?>
<serv:message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<header>
<securityContext>
<webExID>hostid</webExID>
<password>hostpassword</password>
<siteID>0000</siteID>
<partnerID>9999</partnerID>
<email>[email protected]</email>
</securityContext>
</header>
<body>
<bodyContent xsi:type=
"java:com.webex.service.binding.attendee.CreateMeetingAttendee">
<person>
<name>alterhost</name>
<address>
<addressType>PERSONAL</addressType>
</address>
<email>[email protected]</email>
<type>MEMBER</type>
</person>
<role>HOST</role>
<sessionKey>808961063</sessionKey>
</bodyContent>
</body>
</serv:message>
直到现在我都试过:
XNamespace aw = "http://www.w3.org/2001/XMLSchema-instance";
XNamespace xsi = "java:com.tempService";
XElement root = new XElement(aw + "message",
new XAttribute(XNamespace.Xmlns + "serv", aw),
new XElement("header",
new XElement("securityContext", new XElement("siteID", "123"),
new XElement("partnerID", "111"))),
new XElement("body", new XElement("bodyContent",
new XAttribute("xsitype", xsi),
new XElement("person", new XElement("name", "sample content"),
new XElement("email", "[email protected]")),
new XElement("sessionKey", "###"))));
它的结果以下XML:
<serv:message xmlns:serv="http://www.w3.org/2001/XMLSchema-instance">
<header>
<securityContext>
<siteID>123</siteID>
<partnerID>111</partnerID>
</securityContext>
</header>
<body>
<bodyContent xsitype="java:com.tempService">
<person>
<name>sample content</name>
<email>[email protected]</email>
</person>
<sessionKey>###</sessionKey>
</bodyContent>
</body>
</serv:message>
正如您所看到的,它与请求XML格式不匹配。
问题:
- 从顶部
<?xml version="1.0"?>
丢失。 <serv:message xmlns:serv=...
应该<serv:message xmlns:xsi=...
<bodyContent xsitype="...">
应该<bodyContent xsi:type="...">
我已经通过了http://msdn.microsoft.com/en-us/library/bb387075.aspx,但不能纠正。
任何人都可以帮助我解决这个问题。任何帮助,高度赞赏。
您显示为“示例XML”的文本不是有效的XML(具有未定义的前缀“serv:”)。您将无法使用生成像XDocument这样的有效XML的类型来构造这样的文本。 – 2014-08-29 06:00:21
你是如何编写XML的? – Mrchief 2014-08-29 06:19:43
@AlexeiLevenkov是的,你是对的。我认为''会工作吗? –
2014-08-29 06:31:33