dqpfl2508589 2018-06-02 13:06
浏览 66
已采纳

如何通过xml在日期和时间中使用动态数据发布请求

I wanted to do a post request in the form of XML , but thing is i don't want static data in date and time fields . I wanted to take today's date from system.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<site_banner>
    <title>Behat Test Banner</title>
    <type>site_banner</type>
    <language>en</language>
    <field_banner_message_str>
        <und is_array="true">
            <item>
                <value>Test please ignore</value>
            </item>
        </und>
    </field_banner_message_str>
    <field_banner_type>
        <und>
            <value>success</value>
        </und>
    </field_banner_type>
    <field_banner_start_date>
        <und is_array="true">
            <item>
                <value>
                    <date>06/01/2018</date>
                    <time>07:30:00</time>
                </value>
            </item>
        </und>
    </field_banner_start_date>
    <field_banner_end_date>
        <und is_array="true">
            <item>
                <value>
                    <date>06/01/2018</date>
                    <time>08:30:00</time>
                </value>
            </item>
        </und>
    </field_banner_end_date>
</site_banner>

This is the post call i am making , so is there any way we can make date and time dynamic according to system. I have tried including some code in JavaScript but did't work. It will be great help, as i am quiet new to API automation.

  • 写回答

1条回答 默认 最新

  • dongwei1921 2018-06-05 11:25
    关注

    So i have been trying to solve this issue and found out we change the node data in XML.

    <field_banner_start_date>
            <und is_array="true">
                <item>
                    <value>
                        <date>$STARTDATE</date>
                        <time>$STARTTIME</time>
                    </value>
                </item>
            </und>
        </field_banner_start_date>
    
    if (strpos($node_data, '$STARTDATE') !== FALSE) {
         $node_data = str_replace('$STARTDATE', date('m/d/Y'), $node_data);  
    }
    

    So now here every time whne this code will run it will override node data of $STARTDATE to today's date and time.

    Thanks for replying on my question! If this helps anybody i am glad!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图