首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在scxml文件的<data>元素中编写语法规则?

如何在scxml文件的<data>元素中编写语法规则?
EN

Stack Overflow用户
提问于 2015-06-05 03:05:13
回答 1查看 132关注 0票数 1

我很难弄清楚如何在scxml文件中直接内联编写语法规则,而不是在外部grxml文件中链接到它们。

让我举个例子来说明一下:

代码语言:javascript
复制
combat.scxml
------------
<?xml version="1.0" encoding="utf-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" xmlns:vxml="http://www.w3.org/2001/vxml" version="1.0" initial="Start">
    <state id="WeaponChoice">
        <onentry>
            <vxml:prompt>What kind of weapon do you want to use?</vxml:prompt>
        </onentry>
        <datamodel>
            <data id="WeaponChoiceGrammar" expr="./combat.grxml#weapon"/>
        </datamodel>
    </state>
</scxml>

combat.grxml
------------
<?xml version="1.0" encoding="utf-8"?>
<grammar>
    <rule id="weapon">
        <one-of>
            <item>sword</item>
            <item>knife</item>
            <item>hammer</item>
            <item>bow</item>
            <item>crossbow</item>
        </one-of>
    </rule>
</grammar>

如果我想在combat.scxml中的元素中内联编写语法规则,我会这样做:

代码语言:javascript
复制
combat.scxml
------------
<?xml version="1.0" encoding="utf-8"?>
<scxml xmlns="http://www.w3.org/2005/07/scxml" xmlns:vxml="http://www.w3.org/2001/vxml" version="1.0" initial="Start">
    <state id="WeaponChoice">
        <onentry>
            <vxml:prompt>What kind of weapon do you want to use?</vxml:prompt>
        </onentry>
        <datamodel>
            <data id="WeaponChoiceGrammar">
                <rule id="weapon">
                    <one-of>
                        <item>sword</item>
                        <item>knife</item>
                        <item>hammer</item>
                        <item>bow</item>
                        <item>crossbow</item>
                    </one-of>
                </rule>
            </data>
        </datamodel>
    </state>
</scxml>

现在,我们假设combat.grxml是这样的:

代码语言:javascript
复制
combat.grxml
------------
<?xml version="1.0" encoding="utf-8"?>
<grammar>
    <rule id="weapon">
        <one-of>
            <item tag="melee"><ruleref uri="#melee"/></item>
            <item tag="ranged"><ruleref uri="#ranged"/></item>
        </one-of>
    </rule>
    <rule id="melee">
        <one-of>
            <item>sword</item>
            <item>knife</item>
            <item>hammer</item>
        </one-of>
    </rule>
    <rule id="ranged">
        <one-of>
            <item>bow</item>
            <item>crossbow</item>
        </one-of>
    </rule>
</grammar>

现在,我如何才能像在前面的例子中那样,在combat.scxml中的元素中编写内联代码呢?

EN

回答 1

Stack Overflow用户

发布于 2016-02-03 18:07:18

根据SCXML建议,这几乎没有定义,这将取决于您的平台。然而,我怀疑对于任何兼容的scxml解释器,仅仅混合vxml和SCXML名称空间就足够了。您很可能需要调用VoiceXML浏览器并将VoiceXML标记作为发送请求的一部分发送,或者为vxml命名空间中的可执行内容提供自定义元素。

有一些初步支持将JVoiceXML VoiceXML解释器作为uSCXML中的调用器(通过W3C MMI生命周期事件),您可以将自己的元素注册为自定义名称空间中的可执行内容,允许这两种方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30652057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档