导入 xml 文件并引用 xsd 文件

发布于 2024-11-09 16:08:08 字数 419 浏览 0 评论 0原文

我正在尝试找到一种方法来导入 xml 文件,其中 xsd 是一个单独的文件(未嵌入 xml 中)。

 Application.ImportXML DataSource:=varResult, ImportOptions:=acAppendData

是我知道如何导入 xml 文件的基本方法(其中 varResult 是从 FilePicker 例程传递的变量)。据我所知,您可以使用三个基本论点,这与我想要表达的内容无关。如果我要导入我拥有的 xml 文件,它不会为其中一个表创建多个记录;相反,这些值只会覆盖以前的记录。

我知道如何使用节点列表遍历节点,手动获取值,循环遍历,构建临时表,并将数据从临时表迁移到 proTables,但这需要大量编码,只是为了弥补事实上,我只是不知道如何以编程方式引用 xsd 文件,以便使用通用导入命令。

I am trying to find a way to import an xml file, with an xsd that is a seperate file (not embedded in the xml).

 Application.ImportXML DataSource:=varResult, ImportOptions:=acAppendData

is the basic way I know how to import an xml file (where varResult is a variable being passed form a FilePicker routine). As far as I know there are three basic arguments you can use, and this has nothing to do with what I am trying to get at. If I was to import the xml file I have it would not create multiple records for one of the tables; rather those values would just overwrite the previous record.

I know how to just go through the nodes, with nodelist, grab the values manually, loop through that, build temp tables, and migrate the data from the temps to the proTables, but that is alot of coding, just to make up for the fact that I just don't know how to programmatically reference an xsd file, in order to use the generic import command.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

殊姿 2024-11-16 16:08:08

AFAIK 没有 ImportXML 选项来引用单独的 xsd 文件。但既然您知道 xml 和 xsd 文件的名称和位置,也许您可​​以合并它们并将合并文件提供给 ImportXML。

我自己没有尝试过,但怀疑您可以通过两种方式进行合并:

  1. 将 xsd 标记行添加到 xml 文件的根目录
  2. 更改 xml 数据根目录以包含 xsi:noNamespaceSchemaLocation="YourXsdFile.xsd"

这两种方法看起来都有些笨拙。问题是...您是否可以使用比打开 xml 文档然后解析和存储值所需的代码少得多的代码来完成此操作?

AFAIK there is no ImportXML option to reference a separate xsd file. But since you know the names and locations of your xml and xsd files, perhaps you could merge them and feed to merged file to ImportXML.

I haven't tried this myself, but suspect you could do the merge in 2 ways:

  1. add the xsd tag lines to the xml file's root
  2. change the xml dataroot to include xsi:noNamespaceSchemaLocation="YourXsdFile.xsd"

Both of those approaches seem kind of kludgey. The question is ... can you do it with significantly less code than it takes to open the xml doc and then parse and store the values?

倚栏听风 2024-11-16 16:08:08

我认为 ImportXML 方法不够强大,无法完成您想做的事情。如果您已经在使用 AppendData 选项,并且它没有将数据附加到您的规范中,那么我相信您将必须找出一种不同的方法来执行此操作。

在我自己的ExportXML实验中,我认为数据结构定义包含在XML文件中。我认为 Import XML 也期待同样的结果,并且没有给您其他选择。

您已经表明您已经知道如何加载 XML 文件并迭代它以导入数据。我的研究表明,如果 ImportXML 文件没有执行您需要的操作,则没有简单的方法可以将 XML 文件导入到现有表中。您可以通过将 XML 文件加载为 ADO 记录集来简化手动导入。

看看这个相关链接:
http://bytes.com/topic/access/answers/504646 -append-ado-recordset-table

I don't think the ImportXML method is robust enough to do what you want to do. If you're already using the AppendData option and it isn't appending data to your specifications then I believe you'll have to figure out a different way of doing it.

In my own experiments ExportXML, I think the data structure definition is included in the XML file. I think Import XML is expecting the same and gives you no other option.

You've indicated that you already know how to load the XML file and iterate through it in order to import your data. My research shows that there is no simple way to import an XML file into an existing table if the ImportXML file doesn't do what you need it to do. You could possibly simplify the manual import by loading the XML file as an ADO Recordset.

Take a look at this related link:
http://bytes.com/topic/access/answers/504646-append-ado-recordset-table

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文