- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试根据它引用的模式验证 XML 文件。 (使用 Delphi 和 MSXML2_TLB。)代码的(相关部分)看起来像这样:
procedure TfrmMain.ValidateXMLFile;
var
xml: IXMLDOMDocument2;
err: IXMLDOMParseError;
schemas: IXMLDOMSchemaCollection;
begin
xml := ComsDOMDocument.Create;
if xml.load('Data/file.xml') then
begin
schemas := xml.namespaces;
if schemas.length > 0 then
begin
xml.schemas := schemas;
err := xml.validate;
end;
end;
end;
结果是加载了缓存 (schemas.length > 0
),但接下来的赋值会引发异常:“只能使用 XMLSchemaCache-schemacollections。”
我该怎么办?
最佳答案
我想出了一个似乎有效的方法。我首先显式加载架构,然后将它们添加到架构集合中。接下来我加载 xml 文件并将 schemacollection 分配给它的 schemas 属性。解决方案现在看起来像这样:
uses MSXML2_TLB
That is:
// Type Lib: C:\Windows\system32\msxml4.dll
// LIBID: {F5078F18-C551-11D3-89B9-0000F81FE221}
function TfrmMain.ValidXML(
const xmlFile: String;
out err: IXMLDOMParseError): Boolean;
var
xml, xsd: IXMLDOMDocument2;
cache: IXMLDOMSchemaCollection;
begin
xsd := CoDOMDocument40.Create;
xsd.Async := False;
xsd.load('http://the.uri.com/schemalocation/schema.xsd');
cache := CoXMLSchemaCache40.Create;
cache.add('http://the.uri.com/schemalocation', xsd);
xml := CoDOMDocument40.Create;
xml.async := False;
xml.schemas := cache;
Result := xml.load(xmlFile);
if not Result then
err := xml.parseError
else
err := nil;
end;
重要的是使用 XMLSchemaCache40 或更高版本。早期版本不遵循 W3C XML Schema 标准,而是仅针对 MicroSoft 规范 XDR Schema 进行验证。
此解决方案的缺点是我需要显式加载架构。在我看来,应该可以自动检索它们。
关于xml - 在 delphi 中使用 msxml 进行模式验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/446635/
网络服务器正在返回状态代码和描述以响应 XmlHttp 的请求。成分。来自服务器的实际状态响应开头为: HTTP/1.1 400 Not a valid http POST request 我可以在
因此,我正在从事一个项目,根据每个来源的特点,使用许多不同的方法从互联网上的许多不同来源抓取和收集数据。 最近添加的是一个网站 API调用返回以下 XML作为回应: 29b526a69b9
我有一个使用 PHP (libxml) 附带的 XSL 处理器运行的 XSLT 1.0 样式表。我想让相同的样式表在 Microsoft XSL 处理器 MSXML 6.0 (msxml6.dll)
Windows有许多可以并行安装的MSXML版本。即3、4、5和6版。 我必须找到系统上存在哪个msxml文件。我的查询仅通过注册表限制。 最佳答案 您的计算机上安装的所有MSXML版本都将在以下注册
我正在使用 MSXML 6.0 将我自己的 XML 转换为另一种 XML 格式。我不确定我是否只是不明白 MSXML 是如何工作的,但我相信我已经注意到它的一些奇怪行为...... 我正在使用 set
我想在 VBA 中使用 MSXML 创建 XML。目标输出非常基本: 2021-11-10
假设我有一个计算 XPath 表达式“//node/@*”的结果。 MSXML6 返回一组 IXMLDOMNode 对象,它们实际上是 IXMLDOMAttribute 对象。 问题:有没有办法删除仅
XMLNotepad 在转换失败时提供以下文本(例如): Error Transforming XML The variable or parameter 'saturated-background-
我有一个应用程序,用于使用 dll 中的一些遗留代码来测试制造的产品。该应用程序可以针对不同的产品进行设置。设置是通过 xml 文件完成的,并且可以(并且将会)在运行时(即批处理结束时)进行更改。 x
我需要解析一些 XML 并编写一些帮助程序。我不是 C++ 专家,实际上我七年前就用 c 编写过。所以,我想确定一下,我使用的方法是否正确:) 1) 我实现了一些简单的助手来处理异常。例如: CCom
我必须处理一个遗留应用程序,该应用程序使用 MSXML 将测量数据写入一个简单的 XML 文件。基本上,这就是正在发生的事情: MSXML2::IXMLDOMDocument2Ptr pXmlDocu
这似乎是一个常见问题,尽管我在 SO 上找不到它。 我应该在我的应用程序中使用哪个版本的 MSXML,更重要的是,我应该如何决定? 有 MSXML3、4、5 和 6。 我最近在 calling-wcf
我正在开发一个自动化测试应用程序,目前正在编写一个函数来比较两个 XML 文件之间的值,这些文件应该相同,但可能不相同。这是我尝试处理的 XML 示例:
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
使用此代码获取站点的 rss。此代码适用于我的计算机和许多其他计算机。但在某些计算机(Windows XP 或 7)中,我收到此错误:未安装 MSXML 我该如何解决这个问题?怎么了? 代码如下: p
我正在使用 MSXML 4 生成以下 xml 字符串: 但是,我的 IXMLDOMDo
我如何将架构添加到 IXMLDOMDocument ? 例如,我想生成 XML: 我可以构造 DOMDocument60 对象(伪代码): DOMDocument60 doc = new
MSXML6 应该具有最佳的安全性、性能、可靠性和 W3C 一致性 ( Using the right version of MSXML in Internet Explorer )。 问题: 为什么
我使用导入了 MSXML 的 Visual Studio C++ (#import "msxml6.dll") 使用智能指针创建 xml 文档。 我使用 setProperty() 函数创建命名空间,
我有一个 users.xml 我使用以下代码获得了对 Users 元素的引用 IXMLDOMDo
我是一名优秀的程序员,十分优秀!