怎么用C语言写一个简单的XML文件

怎么用C语言写一个简单的XML文件

本文目录

  • 怎么用C语言写一个简单的XML文件
  • c语言如何调用xml的接口函数
  • 用C语言读取xml文件,怎么实现
  • C语言xml解析
  • 如何使用c解析xml
  • c++ C软件编程中使用XML的主要作用是干什么
  • c语言如何解析xml并将所有内容存入数组
  • 如何在C 实现自定义XML序列化问题,怎么解决
  • 怎么用c语言解析xml文件
  • 如何用C语言实现对xml文件的加密

怎么用C语言写一个简单的XML文件


用VC吧,下面有一个例子,你参照下:

void CreateXml()
{
    CoInitialize(NULL);
    // 创建文档
    MSXML2::IXMLDOMDocument2Ptr pXMLDoc = NULL;
    //创建DOMDocument对象
    HRESULT hr = pXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument));
    if (!SUCCEEDED(hr))
    {
        return;
    }
    // Create the Processing Instruction
    MSXML2::IXMLDOMProcessingInstructionPtr pXMLProc = NULL;
    pXMLProc = pXMLDoc-》createProcessingInstruction(“xml“, “version=’1.0’ encoding=’UTF-8’“);
    
    _variant_t vNullVal;
    vNullVal.vt = VT_NULL;
    pXMLDoc-》insertBefore(pXMLProc, vNullVal);
    // 创建根结点
    _variant_t varNodeType((short)MSXML2::NODE_ELEMENT);
    MSXML2::IXMLDOMNodePtr pXMLNodeRoot= NULL; 
    pXMLNodeRoot = pXMLDoc-》createNode(varNodeType, _T(“Cases“), _T(““));
    // 添加根结点
    pXMLDoc-》appendChild(pXMLNodeRoot);
    // 创建并添加下级结点
    MSXML2::IXMLDOMNodePtr pXMLNodeNode= NULL; 
    pXMLNodeNode = pXMLNodeRoot-》appendChild(pXMLDoc-》createElement(_T(“Case“)));
    // 创建下级元素结点
    MSXML2::IXMLDOMElementPtr pXMLEle = NULL;
    pXMLEle = pXMLDoc-》createElement(_T(“CopyFile“));
    // 创建并设置下级结点属性
    MSXML2::IXMLDOMAttributePtr pXMLAttr = NULL;
    pXMLAttr = pXMLDoc-》createAttribute(_T(“src“));
    pXMLAttr-》nodeTypedValue = “C:\\test.txt“;
    pXMLEle-》attributes-》setNamedItem(pXMLAttr);
    pXMLAttr = pXMLDoc-》createAttribute(_T(“dest“));
    pXMLAttr-》nodeTypedValue = “D:\\Test.txt“;
    pXMLEle-》attributes-》setNamedItem(pXMLAttr);
    // 添加元素结点
    pXMLNodeNode-》appendChild( pXMLEle);
    MSXML2::IXMLDOMElementPtr pXMLEle1 = NULL;
    pXMLEle1 = pXMLDoc-》createElement(_T(“DelFile“));
    pXMLEle1-》appendChild(pXMLDoc-》createTextNode(“C:\\test.txt“));
    // 添加元素结点
    pXMLNodeNode-》appendChild( pXMLEle1);
  
    // 保存文档
    pXMLDoc-》save(_T(“d:\\Test.xml“));
}
 
效果如下:
《?xml version=“1.0“ encoding=“UTF-8“ ?》 
《Cases》
    《Case》
        《CopyFile src=“C:\test.txt“ dest=“D:\Test.txt“ /》 
        《DelFile》C:\test.txt《/DelFile》 
    《/Case》
《/Cases》

为了能够让MFC认识MSXML2,我们需要引入相应的dll,代码如下;
#import “msxml4.dll“ 


c语言如何调用xml的接口函数


/***************
《?xml version=“1.0“ encoding=“utf-8“?》
《Cases》
  《case》
    《No》001《/No》
    《CopyFile src=“C:\test.txt“ dest=“D:\test.txt“》《/CopyFile》
  《/case》
  
  《case》
    《No》002《/No》
    《DelFile》C:\test.txt《/DelFile》
  《/case》
《/Cases》
*******************/
// 我们用MFC来读取上述xml,代码如下:
 
void ReadXml(CString strXmlPath)
{
    MSXML2::IXMLDOMDocumentPtr pDoc;
    ::CoInitialize(NULL);
    HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40)); 
    
    if (!SUCCEEDED(hr)) 
    {  
        MessageBox(_T(“创建DOMDocument对象失败。\n请检查运行环境“), _T(“错误“), MB_ICONERROR); 
        return;
    }
    // 读取xml
    pDoc-》put_async(VARIANT_FALSE);
    VARIANT_BOOL bhr = pDoc-》load((_variant_t)strXmlPath);
    if (bhr != VARIANT_TRUE) {
        MessageBox(_T(“无法正确读取xml文件“), _T(“错误“), MB_ICONERROR);
        return;
    }
    // 根节点取得
    MSXML2::IXMLDOMElementPtr root = pDoc-》documentElement;
    // 取得根节点的名字
    _variant_t strRootName = root-》nodeName;
    _bstr_t wstrRootName(strRootName.bstrVal);
    MSXML2::IXMLDOMNodeListPtr nodeList = root-》GetchildNodes();//cases
    
    // 解析cases的子节点
    ReadCases(nodeList);
}
 
void ReadCases(MSXML2::IXMLDOMNodeListPtr nodeList)
{
    int ilength = nodeList-》Getlength();
    for (int nodeCount = 0; nodeCount 《 ilength; nodeCount++) {
        MSXML2::IXMLDOMNodePtr nodePtr = nodeList-》nextNode();
        _variant_t strNodeName = nodePtr-》GetnodeName();
        _variant_t strNodeValue = nodePtr-》GetnodeValue();
 
        // 读取case节点下的子节点
        ReadCase(nodePtr-》GetchildNodes());
    }
}
void ReadCase(MSXML2::IXMLDOMNodeListPtr nodeList)
{
    CString strLogInfo;
    strLogInfo.Empty();
    CString strNo;              // case编号
    CString strSrcFile;         // 源文件
    CString strDestFile;        // 目标文件
    for (int nodeCount = 0; nodeCount 《 nodeList-》Getlength(); nodeCount++)
    {
        MSXML2::IXMLDOMNodePtr nodePtr = nodeList-》nextNode();
        _variant_t strCaseNodeName = nodePtr-》GetnodeName();
        _variant_t strCaseNodeValue = nodePtr-》Gettext();
        BSTR bStrTemp = strCaseNodeName.bstrVal;
        CString strTemp = CString(bStrTemp);
        SysFreeString(bStrTemp);
        CString strNodeName = strTemp;
        //  节点的值,如何取得?
        if (0 == strNodeName.CompareNoCase(_T(“NO“)))
        {
            strNo = (BSTR)strCaseNodeValue.pbstrVal;
            
            // 取得的值可以打印出来
            printf(strNo);
        }
        // 节点有属性值,该怎么处理
        else if (0 == strNodeName.CompareNoCase(_T(“CopyFile“)))
        {
            strSrcFile.Empty();
            strDestFile.Empty();
            // 取得节点的属性值
            MSXML2::IXMLDOMNamedNodeMapPtr pDOMAttrList= nodePtr-》Getattributes();
            for (int j = 0; j 《 pDOMAttrList-》Getlength(); j++)
            {
                MSXML2::IXMLDOMNodePtr pDOMAttr= pDOMAttrList-》Getitem(j); 
                // 取得源文件路径
                if (CompareNoCase((char*)pDOMAttr-》GetnodeName(), _T(“src“)))
                {
                    strSrcFile = pDOMAttr-》GetnodeTypedValue();
                    // 取得目标文件路径
                } else if (CompareNoCase((char*)pDOMAttr-》GetnodeName(), _T(“dest“)))
                {
                    strDestFile =pDOMAttr-》GetnodeTypedValue();
                }
                
                CopyFile(strSrcFile, strDestFile, FALSE);
            }
            else if (0 == strNodeName.CompareNoCase(_T(“DelFile“)))
            {
                strDestFile.Empty();
                strDestFile = CString((BSTR)strCaseNodeValue.pbstrVal);
                
                DeleteFile(strDestFile);
            } 
        }
    }
 // 为了能够让MFC认识MSXML2,我们需要引入相应的dll,代码如下;
#import “msxml4.dll“

用C语言读取xml文件,怎么实现


xml文件和txt文件相同,使用普通的文本操作函数即可读取。

1、C语言标准库提供了一系列文件操作函数。文件操作函数一般以f+单词的形式来命名(f是file的简写),其声明位于stdio.h头文件当中。例如:fopen、fclose函数用于文件打开与关闭;fscanf、fgets函数用于文件读取;fprintf、fputs函数用于文件写入;ftell、fseek函数用于文件操作位置的获取与设置。
2、例程:

#include《stdio.h》
int a;
char b,c;
int main(){
    FILE * fp1 = fopen(“input.xml“, “r“);//打开xml格式输入文件
    FILE * fp2 = fopen(“output.txt“, “w“);//打开输出文件
    if (fp1==NULL || fp2==NULL) {//若打开文件失败则退出
        puts(“不能打开文件!“);
        rturn 0;
    }
    fscanf(fp1,“%d“,&a);//从输入文件读取一个整数
    b=fgetc(fp1);//从输入文件读取一个字符
    fgets(c,100,fp1);//从输入文件读取一行字符串
    
    printf(“%ld“,ftell(fp1));//输出fp1指针当前位置相对于文件首的偏移字节数
    
    fputs(c,fp2);//向输出文件写入一行字符串
    fputc(b,fp2);//向输出文件写入一个字符
    fprintf(fp2,“%d“,a);//向输出文件写入一个整数
    
    fclose(fp1);//关闭输入文件
    fclose(fp2);//关闭输出文件,相当于保存
    return 0;
}

C语言xml解析


把所有的数据当做一个字符串
收到数据后先strstr(buffer,“《?xml version=\“1.0\“ encoding=\“UTF-8\“?》“);
如果返回的是NULL则表示没有这段 退出
buffer是你收到的数据起始地址

如何使用c解析xml


xml文件内容
《?xml version=“1.0“ encoding=“UTF-8“ ?》
- 《aicomoa_response》
- 《country_list》
- 《country》
《id》7《/id》
《pid》0《/pid》
《continent_id》1《/continent_id》
《guohao》93《/guohao》
《cntitle》阿富汗《/cntitle》
《entitle》Afghanistan《/entitle》
《hztitle》阿富汗《/hztitle》
《jptitle》アフガニスタン《/jptitle》
《kotitle》??????《/kotitle》
《jp_pinyin》ア《/jp_pinyin》
《pinyin》AFuHan《/pinyin》
《sid》0《/sid》
《jibie》1《/jibie》
《/country》
- 《country》
《id》8《/id》
《pid》0《/pid》
《continent_id》2《/continent_id》
《guohao》355《/guohao》
《cntitle》阿尔巴尼亚《/cntitle》
《entitle》Albania《/entitle》
《hztitle》阿尔巴尼亚《/hztitle》
《jptitle》アルバニア《/jptitle》
《kotitle /》
《jp_pinyin》ア《/jp_pinyin》
《pinyin》AErBaNiYa《/pinyin》
《sid》0《/sid》
《jibie》1《/jibie》
《/country》
《/country_list》
《/aicomoa_response》
运行结果
Info=[id:7|pid:0|continent_id:1|guohao:93|cntitle:阿富汗|entitle:Afghanistan|
hztitle:阿富汗|jptitle:アフガニスタン|kotitle:??????|jp_pinyin:ア|pinyin:AFuHan|
sid:0|jibie:1|]
Info=[id:7|pid:0|continent_id:1|guohao:93|cntitle:阿富汗|entitle:Afghanistan|
hztitle:阿富汗|jptitle:アフガニスタン|kotitle:??????|jp_pinyin:ア|pinyin:AFuHan|
sid:0|jibie:1|]
Press any key to continue
代码
#include 《stdio.h》
#include 《string.h》
main()
{
int i=0;
FILE *fp;
char szFileBuff = {0}, szBuff;
char id = {0}, pid = {0}, continent_id = {0}, guohao = {0},
cntitle= {0},entitle= {0},hztitle = {0},jptitle = {0},
kotitle = {0},jp_pinyin = {0}, pinyin = {0},sid = {0},jibie = {0};
char *lFirst, *lEnd;

fp = fopen(“country.txt“,“r“);
if (fp==NULL)
{
printf(“read XML file error!\n“);
}
while(fgets(szFileBuff, 1023, fp))
{
if ((lFirst = strstr(szFileBuff, “《id》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/id》“);
memcpy(id, lFirst + 4, lEnd - lFirst - 4);
}
if ((lFirst = strstr(szFileBuff, “《pid》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/pid》“);
memcpy(pid, lFirst + 5, lEnd - lFirst - 5);
}
if ((lFirst = strstr(szFileBuff, “《continent_id》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/continent_id》“);
memcpy(continent_id, lFirst + 14, lEnd - lFirst - 14);
}
if ((lFirst = strstr(szFileBuff, “《guohao》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/guohao》“);
memcpy(guohao, lFirst + 8, lEnd - lFirst - 8);
}
if ((lFirst = strstr(szFileBuff, “《cntitle》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/cntitle》“);
memcpy(cntitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, “《entitle》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/entitle》“);
memcpy(entitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, “《hztitle》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/hztitle》“);
memcpy(hztitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, “《jptitle》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/jptitle》“);
memcpy(jptitle, lFirst + 9, lEnd - lFirst - 9);
}

c++ C软件编程中使用XML的主要作用是干什么


类似于数据库吧,把一些常用的、时不时需要修改值的(工程都很大,你总不能为了只改动代码的几个字母而把整个工程重新编译一遍吧),或者一些起约束作用的配置条件放到XML中,可以起到事半功倍的效果

c语言如何解析xml并将所有内容存入数组


/* 前段时间恰好做过类似的东西,代码可以给你参考下。
 *  Xml配置见最后
 */
typedef struct SrcFileFmt
{
    int   ColID;
    char  ColCode;      /* 字段英文名称 */
    char  ColName;     /* 字段中文名称*/
    char  ColType;      /* 字段类型(包含长度) */
    char  ColComment;  /* 字段描述 */
}SrcFileFmt;
int main(int argc, char **argv)
{
    SrcFileFmt SrcFileFmt;
    int iNum = -1;
    if ( 2 》 argc )
    {
        printf(“Usage: %s SrcXmlFile\n“, argv);
        return -1;
    }
    iNum = parseSourceCfg(SrcCfgFile, SrcFileFmt);
    if (iNum == -1)
    {
        return -1;
    }
    return 0;
}
/* 调用此函数后,xml文件的内容会被存储到结构体数组SrcFileFmt srcfilefmt中
 * 此函数依赖于libxml2-2.9.2.tar.xz
 */
int parseSourceCfg(char *FileName, SrcFileFmt srcfilefmt)
{ /* 解析源文件xml,FileName 为源xml文件名 */
    xmlDocPtr doc;
    xmlNodePtr cur, root;
    char sFileName = {’\0’};
    int cnt = 0;
    if (FileName == NULL)
    {
        return -1;
    }
    sprintf(sFileName, “%s.xml“, FileName);
    doc = xmlParseFile(sFileName);
    if (doc == NULL)
    {
        return -1;
    }
    root = xmlDocGetRootElement(doc);
    if (root == NULL) {
        xmlFreeDoc(doc);
        return(-1);
    }
    if (xmlStrcmp(root-》name, (const xmlChar *) “SrcRoot“))
    {
        xmlFreeDoc(doc);
        return -1;
    }
    
    cur = root-》xmlChildrenNode;
    while (cur != NULL) 
    {
        if ((!xmlStrcmp(cur-》name, (const xmlChar *)“Column“)))
        {
            xmlChar *key;
            xmlNodePtr cur_sub = cur;
            cur_sub = cur_sub-》xmlChildrenNode;
            while (cur_sub != NULL) 
            {
                if ((!xmlStrcmp(cur_sub-》name, (const xmlChar *)“ColID“))) {
                    key = xmlNodeListGetString(doc, cur_sub-》xmlChildrenNode, 1);
                    killblank((char*)key);
                    srcfilefmt[cnt].ColID = atoi((char*)key);
                    xmlFree(key);
                }
                if ((!xmlStrcmp(cur_sub-》name, (const xmlChar *)“ColCode“))) {
                    key = xmlNodeListGetString(doc, cur_sub-》xmlChildrenNode, 1);
                    killblank((char*)key);
                    strcpy(srcfilefmt[cnt].ColCode, (char*)key);
                    xmlFree(key);
                }
                else if ((!xmlStrcmp(cur_sub-》name, (const xmlChar *)“ColName“))) {
                    key = xmlNodeListGetString(doc, cur_sub-》xmlChildrenNode, 1);
                    killblank((char*)key);
                    strcpy(srcfilefmt[cnt].ColName, (char*)key);
                    xmlFree(key);
                }
                else if ((!xmlStrcmp(cur_sub-》name, (const xmlChar *)“ColType“))) {
                    key = xmlNodeListGetString(doc, cur_sub-》xmlChildrenNode, 1);
                     killblank((char*)key);
                    strcpy(srcfilefmt[cnt].ColType, (char*)key);
                    xmlFree(key);
                }
                else if ((!xmlStrcmp(cur_sub-》name, (const xmlChar *)“ColComment“))) {
                    key = xmlNodeListGetString(doc, cur_sub-》xmlChildrenNode, 1);
                    killblank((char*)key);
                    strcpy(srcfilefmt[cnt].ColComment, (char*)key);
                    xmlFree(key);
                }
                cur_sub = cur_sub-》next;
            }
            cnt++;
        }
        cur = cur-》next;
    }
    xmlFreeDoc(doc); 
    return cnt;
}
《SrcRoot》
    《Column》
        《ColID》1《/ColID》
        《ColCode》kmh《/ColCode》
        《ColName》字段1《/ColName》
        《ColType》VARCHAR(11)《/ColType》
    《/Column》
    《Column》
        《ColID》2《/ColID》
        《ColCode》dfkmh《/ColCode》
        《ColName》字段2《/ColName》
        《ColType》VARCHAR(11)《/ColType》
    《/Column》
    《Column》
        《ColID》3《/ColID》
        《ColCode》hbh《/ColCode》
        《ColName》字段3《/ColName》
        《ColType》INTEGER(10)《/ColType》
    《/Column》
《/SrcRoot》

如何在C 实现自定义XML序列化问题,怎么解决


对于字符串,你有一些选择;xml可以简单地用 XmlSerializer ( 或者 DataContractSerializer,但它提供了对xml的更少控制) 或者 JSON (JSON.net, 等来完成。
XmlSerializer的典型类看起来很简单:
public class Apple {
public string Variety {get;set;}
public decimal Weight {get;set;}//etc}
( 注意我也希望上面的Json.NET 也能工作)
上面的类还应该在数据绑定场景中工作良好,这是由于。
你将序列化:
Apple obj = new Apple { Variety =“Cox“, Weight = 12.1M};
XmlSerializer ser = new XmlSerializer(typeof(Apple));
StringWriter sw = new StringWriter();
ser.Serialize(sw, obj);
string xml = sw.ToString();
StringReader sr = new StringReader(xml);
Apple obj2 = (Apple)ser.Deserialize(sr);
但是你可以自定义 xml:
[XmlType(“apple“), XmlRoot(“apple“)]public class Apple {
[XmlAttribute(“variety“)]
public string Variety {get;set;}
[XmlAttribute(“weight“)]
public decimal Weight {get;set;}//etc}
DataContractSerializer 是最理想的,更喜欢:
[DataContract]public class Apple {
[DataMember]
public string Variety {get;set;}
[DataMember]
public decimal Weight {get;set;}}

怎么用c语言解析xml文件


我上次才给人写过
xml文件内容
《?xml version=“1.0“ encoding=“UTF-8“ ?》
- 《aicomoa_response》
- 《country_list》
- 《country》
《id》7《/id》
《pid》0《/pid》
《continent_id》1《/continent_id》
《guohao》93《/guohao》
《cntitle》阿富汗《/cntitle》
《entitle》Afghanistan《/entitle》
《hztitle》阿富汗《/hztitle》
《jptitle》アフガニスタン《/jptitle》
《kotitle》??????《/kotitle》
《jp_pinyin》ア《/jp_pinyin》
《pinyin》AFuHan《/pinyin》
《sid》0《/sid》
《jibie》1《/jibie》
《/country》
- 《country》
《id》8《/id》
《pid》0《/pid》
《continent_id》2《/continent_id》
《guohao》355《/guohao》
《cntitle》阿尔巴尼亚《/cntitle》
《entitle》Albania《/entitle》
《hztitle》阿尔巴尼亚《/hztitle》
《jptitle》アルバニア《/jptitle》
《kotitle /》
《jp_pinyin》ア《/jp_pinyin》
《pinyin》AErBaNiYa《/pinyin》
《sid》0《/sid》
《jibie》1《/jibie》
《/country》
《/country_list》
《/aicomoa_response》
运行结果
Info=[id:7|pid:0|continent_id:1|guohao:93|cntitle:阿富汗|entitle:Afghanistan|
hztitle:阿富汗|jptitle:アフガニスタン|kotitle:??????|jp_pinyin:ア|pinyin:AFuHan|
sid:0|jibie:1|]
Info=[id:7|pid:0|continent_id:1|guohao:93|cntitle:阿富汗|entitle:Afghanistan|
hztitle:阿富汗|jptitle:アフガニスタン|kotitle:??????|jp_pinyin:ア|pinyin:AFuHan|
sid:0|jibie:1|]
Press any key to continue
代码
#include 《stdio.h》
#include 《string.h》
main()
{
int i=0;
FILE *fp;
char szFileBuff = {0}, szBuff;
char id = {0}, pid = {0}, continent_id = {0}, guohao = {0},
cntitle= {0},entitle= {0},hztitle = {0},jptitle = {0},
kotitle = {0},jp_pinyin = {0}, pinyin = {0},sid = {0},jibie = {0};
char *lFirst, *lEnd;

fp = fopen(“country.txt“,“r“);
if (fp==NULL)
{
printf(“read XML file error!\n“);
}
while(fgets(szFileBuff, 1023, fp))
{
if ((lFirst = strstr(szFileBuff, “《id》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/id》“);
memcpy(id, lFirst + 4, lEnd - lFirst - 4);
}
if ((lFirst = strstr(szFileBuff, “《pid》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/pid》“);
memcpy(pid, lFirst + 5, lEnd - lFirst - 5);
}
if ((lFirst = strstr(szFileBuff, “《continent_id》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/continent_id》“);
memcpy(continent_id, lFirst + 14, lEnd - lFirst - 14);
}
if ((lFirst = strstr(szFileBuff, “《guohao》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/guohao》“);
memcpy(guohao, lFirst + 8, lEnd - lFirst - 8);
}
if ((lFirst = strstr(szFileBuff, “《cntitle》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/cntitle》“);
memcpy(cntitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, “《entitle》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/entitle》“);
memcpy(entitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, “《hztitle》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/hztitle》“);
memcpy(hztitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, “《jptitle》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/jptitle》“);
memcpy(jptitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, “《kotitle》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/kotitle》“);
memcpy(kotitle, lFirst + 9, lEnd - lFirst - 9);
}
if ((lFirst = strstr(szFileBuff, “《jp_pinyin》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/jp_pinyin》“);
memcpy(jp_pinyin, lFirst + 11, lEnd - lFirst - 11);
}
if ((lFirst = strstr(szFileBuff, “《pinyin》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/pinyin》“);
memcpy(pinyin, lFirst + 8, lEnd - lFirst - 8);
}
if ((lFirst = strstr(szFileBuff, “《sid》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/sid》“);
memcpy(sid, lFirst + 5, lEnd - lFirst - 5);
}
if ((lFirst = strstr(szFileBuff, “《jibie》“)) != NULL)
{
lEnd = strstr(lFirst + 1, “《/jibie》“);
memcpy(jibie, lFirst + 7, lEnd - lFirst - 7);
}
if ((lFirst = strstr(szFileBuff, “《/country》“)) != NULL)
{
sprintf(szBuff[i],“id:%s|pid:%s|continent_id:%s|guohao:%s|cntitle:%s|entitle:%s|hztitle:%s|jptitle:%s|kotitle:%s|jp_pinyin:%s|pinyin:%s|sid:%s|jibie:%s|“,
id,pid,continent_id,guohao,cntitle,entitle,hztitle,jptitle,kotitle,jp_pinyin, pinyin,sid,jibie);
printf(“Info[%d]=[%s]\n“,i++, szBuff);
}
}
fclose(fp);
}
补充:你这个就说得太笼统了,
1 你上传的xml文件具体格式是什么?
2 要在网页显示的具体格式是什么
3 你根本不知道怎么做 所以也不知道怎么问
我不用关心你的c语言的cgi吧?我才不管是用什么上传的
只有你说的嵌入式三个字 给我一点有用信息 就是解析这个xml用插件恐怕是不行
只能C语言
4 我现在只要求你的xml文件格式和 网页上要显示哪些xml中解析出来的信息
只要知道这些 我只需要在我的程序上加上生成html文件就行了

如何用C语言实现对xml文件的加密


把xml就当做一个普通的二进制文件
然后随便找一个加密算法
按照字节读入xml文件
然后按照加密算法进行加密转换,输出到目标文件就可以了
简单的 可以用异或方式。

免责声明:本网信息来自于互联网,目的在于传递更多信息,并不代表本网赞同其观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,并请自行核实相关内容。本站不承担此类作品侵权行为的直接责任及连带责任。如若本网有任何内容侵犯您的权益,请及时联系我们,本站将会在24小时内处理完毕。
相关文章
返回顶部