【发布时间】:2012-04-14 00:29:45
【问题描述】:
我想通过在 SDL Tridion 2011 中使用核心服务 2011 直接提供 XML 源输入来创建一个组件。
我想编写代码以通过上传源 XML 来创建组件。使用核心服务 2011。
说xml文件的名字是helloworld.xml,位置是D:\abcd\cdef\all\helloworld.xml。
我已经写了这样的代码,但是它不起作用。
XmlDocument contentxml = new XmlDocument();
contentxml.LoadXml(@"D:\abcd\cdef\all\helloworld.xml");
Response.Write("<BR>" + contentxml.ToString());
component.Content = contentxml.ToString();
ComponentData comp = (ComponentData)client.Create(component, new ReadOptions());
Response.write 没有显示任何内容。如果我错过任何事情,请纠正我。
它没有创建任何组件并且错误即将到来。
当我尝试这个时:
XmlDocument contentxml = new XmlDocument();
try
{
contentxml.LoadXml(@"D:\abcd\cdef\all\helloworld.xml");
}
catch (XmlException exp)
{
Console.WriteLine(exp.Message);
}
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
contentxml.WriteTo(xw);
Response.Write("<BR>" + sw.ToString());
component.Content = sw.ToString();
ComponentData comp = (ComponentData)client.Create(component, new ReadOptions());
这次它显示 unable to find UUId: 类似的东西。
我的 helloworld.xml 看起来像这样。
<Content xmlns="uuid:1111eb85-0X11-11f9-1e2X-1X82X78fX920">
<first>Hello World.This is Fisrt field</first>
<second>Hello World.This is second field</second>
</Content>
如果有人分享一些示例代码来做这件事,那就太好了。
【问题讨论】:
-
请说明您迄今为止尝试过的内容 - 最好使用不适合您的代码。就目前而言,您似乎希望人们为您编写代码。
-
老实说,这几乎与 Tridion 无关...无法使用 System.Xml 类加载 XML 文档与 CoreService 或 Tridion 无关...