xml读取节点

本文介绍了一种从XML文件中解析LCD屏幕规格的方法,包括分辨率、脉冲宽度等关键参数,并展示了如何通过C++代码实现这一过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?xml version="1.0" encoding="utf-8"?>
<tplcd type="1" product="JAZZ">
  <lcd_specification>
    <DefaultPicture>jazz_default.bmp</DefaultPicture>
    <!--video or command -->
    <PanelMode>command</PanelMode>
    <PanelWidth>1080</PanelWidth>
    <PanelHeight>1920</PanelHeight>
    <HPulseWidth>0x02</HPulseWidth>
    <HBackPorch>0xF0</HBackPorch>
    <HFrontPorch>0xF0</HFrontPorch>
    <VPulseWidth>0x02</VPulseWidth>
    <VBackPorch>0x10</VBackPorch>
    <VFrontPorch>0x1C</VFrontPorch>
    <!--0x01:board pwr supply  ;  0x02 panel pwr supply; 0x03: advance-->
    <PWMMode>0x02</PWMMode>
    <ColorOrder>BGR</ColorOrder>
    <DPhyNum>0x02</DPhyNum>
  </lcd_specification>

 

    TiXmlDocument doc(XmlFile);
    bool loadOkay = doc.LoadFile();

    if (!loadOkay)
    {
    MessageBox(_T("Could not load file"));    
    exit(EXIT_FAILURE);
    return FALSE;
    }

    //    doc.Print( stdout );
    ofstream outFile;
    outFile.open("test.log",ios_base::app);
    if (!outFile.is_open())//
    {
        cout << "open OUTPUT file error";
        cout << "program terminating.\n";
    
    }
    TiXmlElement* tplcdElement = doc.RootElement();

    TiXmlElement *Lcd_specific = tplcdElement->FirstChildElement("lcd_specification");
    if (Lcd_specific==nullptr)
    {
        MessageBox(_T("NO lcd_specification"));
        return FALSE;
    }

    
    
    TiXmlElement *lspec = Lcd_specific->FirstChildElement();//子节点
    outFile << lspec->Value() << lspec->GetText() << endl;//略去

    TiXmlElement *lllm = lspec->NextSiblingElement();    //
    for (lllm = lspec->NextSiblingElement(); lllm != nullptr; lllm = lllm->NextSiblingElement())//lcd_specification read
    {

        outFile << lllm->Value() << " " << lllm->GetText() << endl;
     
        if (!strncmp(lllm->Value(), "PanelWidth", strlen("PanelWidth")))
        {
            Lcd_Specification.PanelWidth = strtoul(lllm->GetText(), NULL, 0);//str类型转ulong
        }
        if (!strncmp(lllm->Value(), "PanelHeight", strlen("PanelHeight")))
        {
            Lcd_Specification.PanelHeight = strtoul(lllm->GetText(), NULL, 0);//str类型转ulong
        }
        if (!strncmp(lllm->Value(), "PanelMode", strlen("PanelMode")))
        {
            if (!strncmp(lllm->GetText(), "command", strlen("command")))
            {
                Lcd_Specification.PanelMode = 0;// 
            }
            else if (!strncmp(lllm->GetText(), "video", strlen("video")))
            {
                Lcd_Specification.PanelMode = 1;// 
            }

        }
        if (!strncmp(lllm->Value(), "HPulseWidth", strlen("HPulseWidth")))
        {
            Lcd_Specification.HPulseWidth = strtoul(lllm->GetText(), NULL, 0);//str类型转ulong
        }
        if (!strncmp(lllm->Value(), "HBackPorch", strlen("HBackPorch")))
        {
            Lcd_Specification.HBackPorch = strtoul(lllm->GetText(), NULL, 0);//str类型转ulong
        }
        if (!strncmp(lllm->Value(), "HFrontPorch", strlen("HFrontPorch")))
        {
            Lcd_Specification.HFrontPorch = strtoul(lllm->GetText(), NULL, 0);//str类型转ulong
        }

        if (!strncmp(lllm->Value(), "VPulseWidth", strlen("VPulseWidth")))
        {
            Lcd_Specification.VPulseWidth = strtoul(lllm->GetText(), NULL, 0);//str类型转ulong
        }
        if (!strncmp(lllm->Value(), "VBackPorch", strlen("VBackPorch")))
        {
            Lcd_Specification.VBackPorch = strtoul(lllm->GetText(), NULL, 0);//str类型转ulong
        }
        if (!strncmp(lllm->Value(), "VFrontPorch", strlen("VFrontPorch")))
        {
            Lcd_Specification.VFrontPorch = strtoul(lllm->GetText(), NULL, 0);//str类型转ulong
        }
        if (!strncmp(lllm->Value(), "PWMMode", strlen("PWMMode")))
        {
            Lcd_Specification.PWMMode = strtoul(lllm->GetText(), NULL, 0);//str类型转ulong
        }
        if (!strncmp(lllm->Value(), "ColorOrder", strlen("ColorOrder")))
        {
            if (!strncmp(lllm->GetText(), "BGR", strlen("ColorOrder")))
            {
                Lcd_Specification.ColorOrder = 1;
            }
            else if (!strncmp(lllm->GetText(), "RGB", strlen("ColorOrder")))
            {
                Lcd_Specification.ColorOrder = 0;
            }

        }
        if (!strncmp(lllm->Value(), "DPhyNum", strlen("DPhyNum")))
        {
             Lcd_Specification.DPhyNum = strtoul(lllm->GetText(), NULL, 0);//str类型转ulong
        }

    }

 附上经典历程网址http://www.cnblogs.com/ziwuge/archive/2011/08/10/2133534.html

这个温度也很不错http://wenku.baidu.com/link?url=9zPLXHr1PzX3I5oYeCizHe1jTbLqaeL13OTou0YIMaEKtPrwXcnyNIqOcOc2pCqV2SfikG4K8KyYu76x7bxttmakqsrbDaQMT9hrCjCnrTO

转载于:https://www.cnblogs.com/xifengib/p/5897257.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值