0
我试图让下面的XML(为第三方,所以需要准确),并具有对内部元件一些麻烦与的xmlns:使用名称空间创建XElement?
<headerResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<sessionID xmlns="http://www.example.com/portal-api">4654654564</sessionID>
<uniqueTranID xmlns="http://www.example.com/portal-api">gh0000000</uniqueTranID>
<statusCode xmlns="http://www.example.com/portal-api">1</statusCode>
<statusCodeDescription xmlns="http://www.example.com/portal-api">jhkjhkjhkjhkjkjhkjkkjhkhk</statusCodeDescription>
<message xmlns="http://www.example.com/portal-api">testMessage</message>
</headerResponse>
从其他的例子,我已经拿到了以下:
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
XNamespace xsd = "http://www.w3.org/2001/XMLSchema";
XNamespace api = "http://www.example.com/portal-api";
XElement example = new XElement("headerResponse",
new XAttribute(XNamespace.Xmlns + "xsi", xsi),
new XAttribute(XNamespace.Xmlns + "xsd", xsd),
new XElement("sessionID", "some session id", new XAttribute("xmlns", api))
);
没有会话ID,它高兴地创建主headerResponse与XSI和XSD,但是当我加入的SessionID中,并尝试与example.toString()张贴在即时窗口中的内容,我得到以下错误:
The prefix '' cannot be redefined from '' to 'http://www.example.com/portal-api' within the same start element tag.
那(第一个例子)是PERFECT – Sean