【发布时间】:2014-08-29 05:36:23
【问题描述】:
我想创建一个 XML,该 XML 将与请求一起发送到第 3 方站点以创建会议参与者。
文档位于: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>johnsmith@xyz.com</email>
</securityContext>
</header>
<body>
<bodyContent xsi:type=
"java:com.webex.service.binding.attendee.CreateMeetingAttendee">
<person>
<name>alterhost</name>
<address>
<addressType>PERSONAL</addressType>
</address>
<email>host1@test.com</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", "xyz@domain.com")),
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>xyz@domain.com</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:”)。您将无法使用产生有效 XML 的类型(如
XDocument)来构造此类文本。 -
你是如何写出 XML 的?
-
@AlexeiLevenkov 是的,你是对的。我认为
<serv:message xmlns:serv="http://www.w3.org/2001/XMLSchema-instance">会起作用吗? -
@Mrchief:我正在通过 root.ToString() 测试 XML 输出。
-
当你解决完这个问题后,对思科大喊大叫,因为他们在其中一个示例中提供了无效的 XML。