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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?