I am try to use "logical and" in voicexml(with Viecore extensions)
Here is my code:
<if cond="(menuChangeOn == 'YES')&&(businessGroup == '<%=Viecore.ABCCompany.DataAccess.Constants.CURRENT_MODULE.Main_Number%>')">
The "&&" seems to cause trouble while the voice xml file is parsed.
What's the best practice to resolve this common problem?
It XML, so you must use XML entities & for the ampersand symbol. So instead of &&, use &&.
Related
Is there any built-in tag for block, line or in-line comments for the parser generator?
e.g.
comment blocks "(*" Exp "*)" or inline comments "//" Exp.
In a parser generator like menhir, I would normally handle comments by pattern matching with the lexer, so comments wouldn't be part of the AST. Is there an equivalent in K?
If not, what is the recommended way of implementing comments?
You can declare the builtin sort #Layout to be the concatenation via pipes of a set of regular expression terminals (i.e., r"//[^\\n]*"). Any tokens which lex as one of these tokens are simply discarded by the lexer and the parser does not even see them. Note that this applies only to parsing terms using a generated parser or kast; parsing rules in .k files will still require the usual K syntax for comments.
Note that this is also how whitespace is parsed, so unless your language is whitespace sensitive, make sure to include in #Layout any whitespace characters which you want the parser to ignore.
I have an XML document containing a number of XML Processing Instructions which are of the form:
<?cpdoc something?>
I am trying to match them in awk with the pattern
/^\<\?cpdoc/
but it's not returning anything. If I remove the ^ anchor, it works (but I have other similar PIs which don't start a line which I don't want matched).
It looks as if it's being confused by the \<\? but why is it ignoring the line-start anchor?
Don't parse XML with regex, use a proper XML/HTML parser.
theory :
According to the compiling theory, XML can't be parsed using regex based on finite state machine. Due to hierarchical construction of XML you need to use a pushdown automaton and manipulate LALR grammar using tool like YACC.
realLife©®™ everyday tool in a shell :
You can use one of the following :
xmllint
xmlstarlet
saxon-lint (my own project)
Check: Using regular expressions with HTML tags
Example using xpath :
xmllint --xpath '//processing-instruction()' file.xml
Solution by OP and explanation by Ed Morton.
It works if the less-than is not escaped, as otherwise it's a word boundary. So instead of:
\<\?
I should use literal:
<\?
This is because we can't just go escaping any character and hoping for the best, we have to know which characters are metacharacters and then escape them if we want them treated as literal.
I've seen some answers to this in other programming languages, but not a specific erlang one. I'm able to read the file and I use:
re:replace(Subject, RE, Replacement, Options)
specifically:
re:replace(Content, "\r" , " ",[global,{return,list}]),
to remove those escape sequences (I believe that's what they are called)
And it perfectly replaces all the \r with a space. So my question is:
1) is there a way to put multiple replacements in RE, so I could also remove "\n"?
2) is there a different/better/more efficient way to do it?
It's the basics of regular expressions.
In your first question, you can use the solution:
re:replace(Content, "[\r\n]", " ", [global, {return, list}])
Erlang string syntax is not convenient enough, if you need to do a lot of very complex string processing, you should consider using another language.
Azure Search documentation denotes that in Lucene query syntax in Azure Search next "and" operators can be used: AND & +, but why I am getting different sets of results for next two semantically equivale queries:
search=tec AND pro&queryType=full&$count=true
search=tec %26 pro&queryType=full&$count=true //%26 is encoded &
Edited: fixed ampersand encoded code, thanks femtoRgon
Thanks for reporting this. This is a bug in our documentation. Please use && (%26%26, url encoded) for the operator AND and || (%7C%7C, url encoded) for OR. We will fix our documentation asap.
Nate
I am parsing XML Data using NSXMLParser and I notice now, that the Elements can contain ALL characters, including for example a &. Since the parser is giving an error when it comes across this character I replaced every Occurence of this character.
Now I want to make sure to handle every of these characters that may cause Errors.
What are they and how do you think I should handle these characters best?
Thanks in advance!
To answer half your question, XML has 5 special characters that you may want to escape:
< -- replace with <
> -- replace with >
& -- replace with &
' -- replace with '
and
" -- replace with "
Now, for the other half--how to find and replace these without also replacing all the tags, etc... Not easy, but I'd look in to regular expressions and NSRegularExpression: http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSRegularExpression_Class/Reference/Reference.html
Remember, depending on your use case, to escape the values of the parameters on tags, too; <tag parameter="with "quotes"" />
You should encode these characters for instance & becomes & or " becomes "
When it goes through the parser it should come out ok. Your other option is to use a different XML parser like TBXML which doesn't do format checking.