使用Java DOM解析器解析XML文件会导致:
[Fatal Error] os__flag_8c.xml:103:135: An invalid XML character (Unicode: 0xc) was found in the element content of the document.
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xc) was found in the element content of the document.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
Run Code Online (Sandbox Code Playgroud) 我不敢相信以前没有问过这个问题.我有一个字符串需要插入HTML文件,但它可能包含特殊的HTML字符.我想用适当的HTML表示替换它们.
下面的代码有效,但非常冗长和丑陋.性能对我的应用程序并不重要,但我想这里也存在可伸缩性问题.我怎样才能改善这个?我想这是STL算法或一些深奥的Boost函数的工作,但下面的代码是我能想出的最好的代码.
void escape(std::string *data)
{
std::string::size_type pos = 0;
for (;;)
{
pos = data->find_first_of("\"&<>", pos);
if (pos == std::string::npos) break;
std::string replacement;
switch ((*data)[pos])
{
case '\"': replacement = """; break;
case '&': replacement = "&"; break;
case '<': replacement = "<"; break;
case '>': replacement = ">"; break;
default: ;
}
data->replace(pos, 1, replacement);
pos += replacement.size();
};
}
Run Code Online (Sandbox Code Playgroud) 在我的web.config中的AppSettings中,我有这样的事情:
<appSettings>
<add key="ExternalSystemUrl" value="http://domain.com/page.aspx?id={0}&action=eat&object=bacon" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
但是,似乎当一个&符号(&)包含在AppSettings值中时,ASP.NET会抛出以下错误:
解析EntityName时发生错误
为什么会发生这种情况,如何在App.config中包含这样的URL?
我需要通过maven属性设置一个URL(每个配置文件要替换).问题是这个URL包含一些&而maven不喜欢这个(如果URL包含&_program):
"对实体的引用"_program"必须以';'结尾 分隔符".此行上的pom发生错误.
那么如何逃避这个角色或如何逃避可能包含一些"特殊"角色的洞线.(属性值中禁止使用哪些其他字符?)
什么时候我们应该用< > & " 'XML 替换<等字符等.
我的理解是,只是为了确保如果XML的内容部分具有> <解析器将不会处理标记的开始或结束.
另外,如果我有一个XML:
<hello>mor>ning<hello>
Run Code Online (Sandbox Code Playgroud)
应该替换为:
<hello>mor>ning<hello><hello>mor>ning<hello><hello>mor>ning<hello>我不明白为什么需要更换.什么时候需要它,究竟应该更换什么(标签或文字)?
我在D:目录中有一个名为/NewFile.xml的XML文件.XML文件包含以下详细信息:
<?xml version="1.0"?>
<project>
<logindetails id="1001">
<url>https:xxx</url>
<username>xxx</username>
<password>xxx</password>
</logindetails >
<kpi id="1001">
<id_r>reports</id_r>
<id_e>extranet</id_e>
<id_pr>ext-pr</id_pr>
</kpi>
<prkpi id="1001">
<id_1>ext-pr-backlog-age</id_1>
<id_2>ext-timetoassign-prs</id_2>
<id_3>ext-timetodeliver-prs</id_3>
<id_4>ext-timetoresolve-prs</id_4>
<id_5>ext-new-prs</id_5>
</prkpi>
<filtersection id="1001">
<visualizationId>Day,Week,Month,Quarter,Semester,Year,RD Tech Group,ICC,Center,Software Pack,Product,Project,Customer PRs,Severity,Priority</visualizationId>
<projectId>dev/v4.3/r4/e12sqq,BATS,1523 Business IAD & Business CPE,[CoCo2M],VQM</projectId>
</filtersection>
</project>Run Code Online (Sandbox Code Playgroud)
我在eclipse中运行的代码如下:
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.w3c.dom.Document;
import …Run Code Online (Sandbox Code Playgroud)我应该如何在包含撇号的XML中编写元素值?是否存在相同的转义序列?
我正在动态地获取一个xml,类似于sql Select.现在在这种情况下,emp_name O''DELL,SEAN本身就包含撇号.我应该如何获得emp_name,以便形成一个合适的xml?
<Result type="Benefit" emp_id='332' emp_name='O''DELL, SEAN '/>
Run Code Online (Sandbox Code Playgroud)
多谢你们.
我有一个字符串,上面写着"以下字符无效:"!@#$%^ \&*()/ \或空格"我不知道如何将&符号放入xml文件而不会导致错误?我知道你应该按照\&但我不确定它到底是什么?
我想<res>在android中创建一个字符串,如下所示:
<string name="bmi0">0: BMI?18.5</string>
<string name="bmi1">1: 18.5<BMI?24</string>
<string name="bmi2">2: 24<BMI?27</string>
Run Code Online (Sandbox Code Playgroud)
但我显示"标签启动未关闭"的错误.
我试图\在前面放一个符号,但它不起作用,它显示了同样的错误.
<string name="bmi0">0: BMI\?18.5</string>
<string name="bmi1">1: 18.5<BMI\?24</string>
<string name="bmi2">2: 24<BMI\?27</string>
Run Code Online (Sandbox Code Playgroud)
如何逃避特殊的XML符号?