如何用C创建XML文件 [英] How to create XML file with C

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

问题描述

我进行了搜索,不幸的是,我只发现了如何使用C ++或C#进行操作-我曾经是面向对象的语言,这与我大不相同.

你能给我指点一下信息吗?

我只是在放弦:

fputs(< complexType name =" DominantColorType"final ="#all> \ n",fp);

但是我在#"处遇到错误".有人知道为什么吗?

I''ve searched, unfortunately I only found how to do that with C++ or C# - i''s pretty different once are object oriented languages.

Can you please point me to the information?

I was simply putting strings:

fputs("<complexType name=''DominantColorType" final=''#all''>\n",fp);

But I get an "error" at ''#''. Anyone know why ?

推荐答案

[
Does this[^] help? I''ve not used it, just found it with a quick search.


思想:
fputs("<complexType name='DominantColorType" final='#all'>\n",fp);



仔细看看DominantColorType"

您可能是说DominantColorType''

对于纯c实现:
Gnome的XML C解析器和工具包
[^ ]

并且有 Apache Xerces [



Take a closer look at DominantColorType"

you probably meant DominantColorType''

For a pure c implementation:
The XML C parser and toolkit of Gnome
[^]

and the there is this Apache Xerces[^] - it''s C++ though

Regards
Espen Harlinn


所有您需要自己编写代码,并且首先必须了解XML.

我可以给一些提示

您需要像这样定义宏
All you need to write your code by own and first of all you must know XML.

I just can give some hints

You need to define your macros like this
<pre lang="xml">#include <stdio.h>
#include <tchar.h>
#define START_NODE( \
     /*NULL TERMINATED STRING*/NodeName , \
     FilePointer) \
     fprintf( FilePointer , "<%s>\n" , NodeName ) \
#define END_NODE( \
     /*NULL TERMINATED STRING*/NodeName , \
     FilePointer) \
     fprintf( FilePointer , "</%s>\n" , NodeName ) \
int _tmain(int argc, _TCHAR* argv[])
{
    FILE *fp = NULL;     /*i use stdout in place of a file pointer
                         to show the result on concole*/
    START_NODE("t1", stdout);
    END_NODE("t1", stdout);
    getchar();
    return 0;
}




但是使用这些宏您不能将属性赋予节点 ...

如果您不需要属性,则可以执行此操作....

如果需要的话,使用函数代替宏 ...




but using these MACROs you can''t give attributes to nodes...

This will do if you don''t need attributes....

If you want then use functions instead of macros...


这篇关于如何用C创建XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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