使用xslt在c中创建xml文件 [英] using xslt to create an xml file in c

查看:79
本文介绍了使用xslt在c中创建xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有5个不同的键/值对,我知道xml文件的外观.如何从中创建xml文件? 1)我总是可以做printf()-不好. 2)我可以使用xslt(样式表(.xsl)文件)吗?

I have 5 different key/value pairs and I know how my xml file should look. How can I create an xml file out of it? 1) I can always do printf() - not preferable. 2) Can I use xslt (stylesheet (.xsl) file) to do that?

而且,我还希望能够执行我刚才提到的操作的相反操作.给定一个xml文件,我想提取这5个键/值对.我想,我肯定需要xsl文件来执行此操作.

And, I also want to be able to do the reverse operation of what I just mentioned. Given an xml file, I want to extract those 5 key/value pairs. I guess, I would need xsl file for this operation for sure.

关于是否可行,我只需要一个起点.我可以用C编写自己的代码.

I just need a starting point in terms of whether is doable or not. I can code myself in C.

示例xml文件:

<element1 type="type1" name="value1">
  <start play="no"/>
  <element2 aaa="AAA"/>
  <element2 bbb="BBB"/>
  <element3 ccc="CCC">
     <element4/><!-- play="no"/>-->
  </element3>
</element1>

推荐答案

听起来像您在寻找 libxml2 ,它使您可以从C读取和写入XML.它非常易于使用,并且有几个 xml编写器示例.

Sounds like you're looking for libxml2, which allows you to read and write XML from C. It's very easy to use, and has several xml writer examples.

如果您想阅读XML,请查看其xml阅读器示例 ,或其解析示例.

If you want to read XML in, take a look at their xml reader examples, or their parsing examples.

如果要从C语言执行XSLT,也可以使用 libxslt libxml2.虽然,如果您想将值读入代码中的变量中,那么最好使用libxml2解析器. XSLT更适合将XML文件转换为另一个XML文件.

If you want to do XSLT from C, you can also use libxslt, which is built on top of libxml2. Although, if you want to read the values into variables in your code, you'd probably be better off just with the libxml2 parsers. XSLT is better for transforming an XML file into another XML file.

这篇关于使用xslt在c中创建xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆