我有一个xml URL文件,其中有空格我想用%20替换空格..怎么做????
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL(
"http://www.arteonline.mobi/iphone/output.php?gallery=MALBA%20-%20MUSEO%20DE%20ARTE%20LATINOAMERICANO%20DE%20BUENOS%20AIRES");
XMLHandlerartistspace myXMLHandler = new XMLHandlerartistspace();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
Run Code Online (Sandbox Code Playgroud) 我当然熟悉这些java.net.URLEncoder和java.net.URLDecoder课程.但是,我只需要HTML风格的编码.(我不想' '替换'+'等).我不知道在类中构建的JDK只会进行HTML编码.有吗?我知道其他选择(例如,Jakarta Commons Lang'BtringEscapeUtils',但我不想在我需要它的项目中添加另一个外部依赖项.
我希望在最近的JDK(又名5或6)中添加了一些我不知道的JDK.否则我必须自己动手.
我有这个特殊字符的奇怪问题.在JSP中,我使用字段名称作为id,名称可以是任何类似的
id="<1 and &>2" (OR)
id="aaa & bbb"
Run Code Online (Sandbox Code Playgroud)
我没有任何其他选项来使用ID而不是名称,这是我从后端得到的唯一东西.
那么,是否有任何逻辑可以使用JSTL删除所有特殊字符.在目前的场景中,在In JS中,我将使用ID进行一些操作.这导致每种浏览器出现很多问题.
请建议,提前致谢...
在Java中,是否有可用的第三方源或快速命令将字符串中的html特殊字符转换为html编码内容?
例如:
Original code: <>&abcdef ©
After encoding: <>&abcdef©
Run Code Online (Sandbox Code Playgroud) 目前我正在努力在java中转换具有等效字符的HTML代码.我需要将以下代码转换为字符.
è - è
® - ®
& - &
ñ - ñ
& - &
Run Code Online (Sandbox Code Playgroud)
我尝试使用正则表达式模式
(&#x)([\\d|\\w]*)([\\d|\\w]*)([\\d|\\w]*)([\\d|\\w]*)(;)
Run Code Online (Sandbox Code Playgroud)
当我调试时,matcher.find()给我true但控件跳过我编写转换代码的循环.不知道那里发生了什么.
另外,有没有办法优化这个正则表达式?
任何帮助表示赞赏.
例外
java.lang.NumberFormatException: For input string: "x26"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at org.apache.commons.lang.Entities.unescape(Entities.java:683)
at org.apache.commons.lang.StringEscapeUtils.unescapeHtml(StringEscapeUtils.java:483)
Run Code Online (Sandbox Code Playgroud) Android有两种不同的方法来转义/编码Strings中的HTML字符/实体:
Html.escapeHtml(String),在API 16(Android 4.1)中添加.文档说:
返回给定纯文本的HTML转义表示形式.
TextUtils.htmlEncode(String) 对于这个,文档说:
Html编码字符串.
阅读文档,他们似乎都做了几乎相同的事情,但是,在测试它们时,我得到一些非常神秘(对我而言)的输出.
例如.随着输入:<p>This is a quote ". This is a euro symbol: €. <b>This is some bold text</b></p>
Html.escapeHtml 得到:
<p>This is a quote ". This is a euro symbol: €. <b>This is some bold text</b></p>
Run Code Online (Sandbox Code Playgroud)而TextUtils.htmlEncode给出:
<p>This is a quote ". This is a euro symbol: €. <b>This is some bold text</b></p>
Run Code Online (Sandbox Code Playgroud)所以似乎第二个转义/编码引号("),但第一个没有,虽然第一个编码欧元符号,但第二个没有.我很困惑.
那么这两种方法有什么区别呢?每个转义/编码的字符是什么?编码和转义之间的区别是什么?我什么时候应该使用其中一种(或者我应该喘气,一起使用它们?)?
android html-encode html-entities android-webview html-escape
我想用他们的同行替换换行符和空格,以便在我的Android应用程序中正确设置样式.
我想知道这个正则表达式的最佳方法.我试图用以下内容替换新行<br />:
string.replaceAll("@<code>.*\\n*</code>@si", "<br />");
Run Code Online (Sandbox Code Playgroud)
但它没有用.对于替换双倍空间,我无法想出任何东西.
所以这就是我想要实现的目标:
从\n到<br />,并从"双未编码的空间"  .
我怎么能编码"成"和'成'?
我很惊讶单引号和双引号没有在HTML实体4.0中定义,因此StringEscapeUtils无法将这2个字符转义为相应的实体.
还有其他与字符串相关的工具能够做到这一点吗?
HTML实体4.0中没有定义单引号和双引号的原因吗?
除了单引号和双引号之外,是否有任何框架能够将所有unicode字符编码为相应的实体?由于所有的unicode都可以手动转换为十进制实体并以HTML格式显示,所以有什么工具可以自动转换它?
我使用JavaScript将页面源代码(document.getElementsByTagName('html')[0].innerHTML)发送到我的web服务元素中<pagesource>...</pagesource>.显然,那里有HTML标签,因此我在解组时遇到错误.有可能以某种方式解析这个或逃避所有坏人物吗?
ERROR
com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 52; columnNumber: 3; The element type "input" must be terminated by the matching end-tag "</input>".]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:335)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:514)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:215)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:214)
at cz.fit.cvut.swe.pagerating.ws.WebService.addRating(WebService.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:43)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) …Run Code Online (Sandbox Code Playgroud) java ×7
html ×3
android ×2
escaping ×2
html-encode ×2
character ×1
html-escape ×1
javascript ×1
jaxb ×1
jsp ×1
jstl ×1
matcher ×1
regex ×1
urlencode ×1
xml ×1