在XSLT 1.0中,您可以使用以下函数获取XML元素的本地名称或namespaceUri:
string local-name (node)
Run Code Online (Sandbox Code Playgroud)
和
string namespace-uri(node)
Run Code Online (Sandbox Code Playgroud)
但是有一个标准函数来获取具有限定名称的元素的前缀吗?
我正在尝试使用required ="true"进行简单验证
<h:form>
<h:messages globalOnly="true"/>
<h:panelGrid>
<h:panelGrid columns="3">
<f:facet name="header">
Login Application Sample
</f:facet>
<h:outputLabel for="UserId" value="User Id" />
<h:inputText id="UserId" value="#{userBean.userId}" required="true" />
<h:message for="UserId"/>
<h:outputLabel for="Password" value="Password" />
<h:inputSecret id="Password" value="#{userBean.password}" required="true" />
<h:message for="Password" />
<f:facet name="footer">
<h:commandButton value="Login" action="#{userBean.login}"/>
<h:commandButton type="reset" value="Reset"/>
</f:facet>
</h:panelGrid>
</h:panelGrid>
</h:form>
Run Code Online (Sandbox Code Playgroud)
将字段留空,然后单击登录按钮,这些错误消息将显示在每个字段的右侧:
j_idt7:UserId:验证错误:值是必需的.
j_idt7:密码:验证错误:值是必需的.
这是我的预期,但我不想显示'j_idt7:'的表单id前缀.我读过书中的例子,他们不输出表格id前缀.我想要的是:
UserId:验证错误:值是必需的.
密码:验证错误:值是必需的.
如何跳过在组件特定消息中显示表单ID前缀?
我目前正在使用glassfish v3测试JSF 2.
我对使用try尝试的字符串匹配中使用的实际算法并不太精通.
我想知道为什么似乎更关注字符串匹配的后缀尝试而不是前缀尝试.我们可以不使用前缀尝试进行子串匹配吗?换句话说,后缀尝试超过前缀尝试的优点是什么?
我试图在批处理脚本中重命名文件,如下所示:
rename %FOLDER%\* 1-*
Run Code Online (Sandbox Code Playgroud)
但是当我运行脚本时,它会用前缀"1-"覆盖原始名称的前两个字符,而不是将其添加到文件名的开头.我该如何解决这个问题?
我想创建一个可以将数据从数据库显示到JSF页面的表.我找到了这段代码:
<h:dataTable value="#{bookStore.items}" var="store">
<h:column>
<f:facet name="header">
<h:outputText value="#{msg.storeNameLabel}"/>
</f:facet>
<h:outputText value="#{store.name}"/>
</h:column>
<h:column>
<f:facet name="header">
Subject
</f:facet>
<h:outputText value="#{store.subject}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{msg.storePriceLabel}"/>
</f:facet>
<h:outputText value="#{store.price}"/>
</h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)
当我使用此代码时,我在Netbeans中收到此错误消息:
javax.faces.view.facelets.FaceletException:Error Parsing /my.xhtml:Error Traced [line:42]元素"f:facet"的前缀"f"未绑定
如果我用f标签替换h标签,它会起作用吗?或者我是否必须包含f标签库?
我想使用PHP套接字通过网络连接将JSON消息从PHP脚本发送到C#应用程序.
通常,对于二进制协议,每条消息的前4个字节必须是一个整数,表示消息的长度(多少字节).
在C#中,我为每条消息添加一个整数,该整数表示消息的长度,如下所示:
byte[] msgBytes = UTF8Encoding.UTF8.GetBytes("A JSON msg");
byte[] prefixBytes = BitConverter.GetBytes(msgBytes.Length);
byte[] msgToSend = new byte[prefixBytes.Length + msgBytes.Length];
Buffer.BlockCopy(prefixBytes, 0, msgToSend, 0, prefixBytes.Length);
Buffer.BlockCopy(msgBytes, 0, msgToSend, prefixBytes.Length, msgBytes.Length);
Run Code Online (Sandbox Code Playgroud)
据我所知,在PHP中,函数socket_send只接受字符串.那么,我怎么能在PHP 5.x中做同样的前缀呢?
更新:我发布了一个关于如何从网络套接字接收此类前缀数据的后续问题.
我有以下XML:
<ns2:Person name="John" age="20" />
Run Code Online (Sandbox Code Playgroud)
我想将它解组为从XSD生成的JAXB对象Person.
这是我正在运行的代码:
JAXBContext context = JAXBContext.newInstance(PersoEntity.class);
Unmarshaller um = context.createUnmarshaller();
StringReader sr = new StringReader(xml);
Person p = (Person)um.unmarshal(sr);
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是我得到以下异常:
javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: The prefix "ns2" for element "ns2:Person" is not bound.]
Run Code Online (Sandbox Code Playgroud)
我该如何解决?谢谢
我正在使用弹性搜索查询的前缀查询.在顶级数据上使用它时工作正常,但一旦应用于嵌套数据,就不会返回任何结果.我尝试查询的数据如下所示:
这里前缀查询工作正常:查询:
{ "query": { "prefix" : { "duration": "7"} } }
Run Code Online (Sandbox Code Playgroud)
结果:
{
"took": 25, ... },
"hits": {
"total": 6,
"max_score": 1,
"hits": [
{
"_index": "itemresults",
"_type": "itemresult",
"_id": "ITEM_RESULT_7c8649c2-6cb0-487e-bb3c-c4bf0ad28a90_8bce0a3f-f951-4a01-94b5-b55dea1a2752_7c965241-ad0a-4a83-a400-0be84daab0a9_61",
"_score": 1,
"_source": {
"score": 1,
"studentId": "61",
"timestamp": 1377399320017,
"groupIdentifiers": {},
"assessmentItemId": "7c965241-ad0a-4a83-a400-0be84daab0a9",
"answered": true,
"duration": "7.078",
"metadata": {
"Korrektur": "a",
"Matrize12_13": "MA.1.B.1.d.1",
"Kompetenz": "ZuV",
"Zyklus": "Z2",
"Schwierigkeit": "H",
"Handlungsaspekt": "AuE",
"Fach": "MA",
"Aufgabentyp": "L"
},
"assessmentSessionId": "7c8649c2-6cb0-487e-bb3c-c4bf0ad28a90",
"assessmentId": "8bce0a3f-f951-4a01-94b5-b55dea1a2752"
}
}, …Run Code Online (Sandbox Code Playgroud) 我试图通过支持库v7实现ActionBar.因为我想支持Android 2.1(API级别7)及更高版本的应用程序.
我在http://developer.android.com/guide/topics/ui/actionbar.html中读到以下内容:"使用支持库中的XML属性请注意,上面的showAsAction属性使用标记中定义的自定义命名空间.这是必要的使用支持库定义的XML属性时,因为这些属性不会在旧设备上的Android框架存在的.所以,你必须使用自己的名称空间作为由支持库中定义的所有属性的前缀".
我的问题是如何使用自己的命名空间作为支持库定义的所有属性的前缀?
请一步一步解释!//谢谢.
我写下了一个简单的函数,它确定str1是否是str2的前缀.这是一个非常简单的函数,看起来像这样(在JS中):
function isPrefix(str1, str2) // determine if str1 is a prefix of a candidate string
{
if(str2.length < str1.length) // candidate string can't be smaller than prefix string
return false;
var i = 0;
while(str1.charAt(i) == str2.charAt(i) && i <= str1.length)
i++;
if(i < str1.length) // i terminated => str 1 is smaller than str 2
return false;
return true;
}
Run Code Online (Sandbox Code Playgroud)
如您所见,它循环遍历前缀字符串的整个长度,以衡量它是否是候选字符串的前缀.这意味着它的复杂性是O(N),这也不错,但是当我有一个庞大的数据集来考虑循环以确定哪些字符串具有前缀字符串作为前缀的一部分时,这就成了一个问题.这使得复杂性像O(M*N)一样多,其中M是给定数据集中的字符串总数.不好.
我稍微探讨了互联网,以确定最佳答案是Patricia/Radix trie.字符串存储为前缀的位置.即使这样,当我尝试插入/查找字符串时,如果我使用上述前缀测量功能,则字符串匹配会有相当大的开销.
假设我有一个前缀字符串'rom'和一组候选词
var dataset = ["random","rapid","romance","romania","rome","rose"];
在基数trie中想要这样:
r
/ \
a o
/ \ / \
ndom …Run Code Online (Sandbox Code Playgroud) prefix ×10
jsf ×2
namespaces ×2
android ×1
batch-file ×1
facelets ×1
file-io ×1
forms ×1
function ×1
jaxb ×1
matching ×1
messages ×1
php ×1
php-socket ×1
prefix-tree ×1
sockets ×1
string ×1
trie ×1
validation ×1
xml ×1
xslt ×1