我正在尝试用FOAF和Perl做一些事情.我对目前的解决方案不满意,我想自己动手.请不要参考除以外的任何模块XML::LibXML.
这里参考的是FOAF文件的片段
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:admin="http://webns.net/mvcb/">
<foaf:Person rdf:ID="me">
<foaf:name>Evan Carroll</foaf:name>
....
Run Code Online (Sandbox Code Playgroud)
现在,排除空白,我正在尝试重新创建它XML::LibXML.但是,我很遗憾地陷入了第一线.这只关注第一行:
我读到这个
RDF,在命名空间中rdf声明
rdf名称空间属性xmlnshttp://www.w3.org/1999/02/22-rdf-syntax-ns#rdfs名称空间属性xmlnshttp://www.w3.org/2000/01/rdf-schema#foaf名称空间属性xmlnshttp://xmlns.com/foaf/0.1/admin名称空间属性xmlnshttp://webns.net/mvcb/首先你需要一个元素rdf:RDF,这似乎很棘手.阅读我找到的文档,但这似乎没有做我想要的:XML::LibXML::DocumentcreateElementNS()
use XML::LibXML;
my $doc = XML::LibXML::Document->new( '1.0', 'UTF-8' );
my $foaf = $doc->createElementNS( 'RDF', 'rdf' );
print $foaf->toString; # prints <rdf xmlns="RDF"/>
Run Code Online (Sandbox Code Playgroud)
现在,我尝试createElement('rdf:RDF')它的工作原理!我得到了根元素rdf:RDF.这是我们应该如何创建根元素?我只是读错了XML吗?
现在,我需要创建属性(模式声明).我尝试了记录不佳的文件XML::LibXML::Document, …
我正在尝试编写一个XML解析器,它采用RSS提要并获取<media:thumbnail>标记的url属性中显示的图像URL .这一切都是通过完成android.Util.Xml,并且是对此处所示代码的修改.我正在尝试使用的示例RSS源是BBC新闻RSS源.
但是,媒体是一个额外的命名空间&(可能)因此我的解析器不能正常工作.
我的解析方法的一个版本如下.有没有(毫无疑问是简单的)方法来获取我的图像URL列表?
public List<string> parse() {
URL feedUrl = new URL("http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml");
InputStream feedStream;
try {
feedStream = feedUrl.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
final List<string> ret = new ArrayList<string>();
RootElement root = new RootElement("rss");
Element channel = root.getChild("channel");
Element item = channel.getChild("item");
item.getChild("media", "thumbnail").getChild("url").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
ret.add(body);
}
});
try {
Xml.parse(feedStream, Xml.Encoding.UTF_8, root.getContentHandler());
} catch (Exception e) {
throw new …Run Code Online (Sandbox Code Playgroud) 我目前无法尝试使用XSL将XML文档转换为HTML.XML文档使用命名空间,我对XSL没有太多经验,更不用说命名空间了.基本上我想要做的就是获取s:treatment的每个实例并将其作为列表输出.我已经更改了数据,所以不要公开我正在为此做的网站.我正在使用经典ASP(无法更新到ASP.NET)来转换服务器上的XML,因此XSL必须是版本1 :(
我真的很感激任何帮助,因为我无法弄清楚出了什么问题.
这是XML:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">a</title>
<id>a</id>
<rights type="text">© Crown Copyright 2009</rights>
<updated>2011-01-19T11:23:25Z</updated>
<category term="Service"/>
<author>
<name>c</name>
<uri>http://www.meh.com</uri>
<email>erwt</email>
</author>
<complete xmlns="http://purl.org/syndication/history/1.0"/>
<entry>
<id>http://meh.com/services</id>
<title type="text">title</title>
<updated>2010-06-18T19:52:12+01:00</updated>
<link rel="self" title="title" href="meh"/>
<link rel="alternate" title="title" href="id"/>
<content type="application/xml">
<s:service xmlns:s="http://syndication.nhschoices.nhs.uk/services">
<s:type code="S">h</s:type>
<s:deliverer>j</s:deliverer>
<s:parent>k</s:parent>
<s:treatments>
<s:treatment>fissure</s:treatment>
<s:treatment>fistula</s:treatment>
<s:treatment>liver</s:treatment>
<s:treatment>pancreas</s:treatment>
<s:treatment>Cirrhosis</s:treatment>
<s:treatment>Coeliac disease</s:treatment>
<s:treatment>Crohn's disease</s:treatment>
<s:treatment>Diagnostic endoscopy of the stomach</s:treatment>
<s:treatment>Diverticular problems</s:treatment>
<s:treatment>Gastrectomy</s:treatment>
<s:treatment>Gastroenteritis</s:treatment>
<s:treatment>Gastroenterology</s:treatment>
<s:treatment>Gastroesophageal reflux disease(GORD)</s:treatment>
<s:treatment>Hepatitis</s:treatment>
<s:treatment>Hepatitis A</s:treatment>
<s:treatment>Hepatitis B</s:treatment>
<s:treatment>Hepatitis C</s:treatment>
<s:treatment>Hernia hiatus</s:treatment> …Run Code Online (Sandbox Code Playgroud) 我需要创建一个具有以下结构的XML文档:
<?xml version="1.0" ?>
<Cancelacion xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
RfcEmisor="VSI850514HX4"
Fecha="2011-11-23T17:25:06"
xmlns="http://cancelacfd.sat.gob.mx">
<Folios>
<UUID>BD6CA3B1-E565-4985-88A9-694A6DD48448</UUID>
</Folios>
</Cancelacion>
Run Code Online (Sandbox Code Playgroud)
结构必须是这样的.但我不太熟悉XML Elements的名称空间声明.我可以使用以下结构正确生成XML:
<?xml version="1.0" ?>
<Cancelacion RfcEmisor="VSI850514HX4"
Fecha="2011-11-23T17:25:06"
xmlns="http://cancelacfd.sat.gob.mx">
<Folios>
<UUID>BD6CA3B1-E565-4985-88A9-694A6DD48448</UUID>
</Folios>
</Cancelacion>
Run Code Online (Sandbox Code Playgroud)
但问题是我不能正确地包括xmls:xsd和xmlns:xsi.正确生成前面提到的代码的代码是:
// Crear un document XML vacío
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
dbfac.setNamespaceAware(true);
DocumentBuilder docBuilder;
docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();
doc.setXmlVersion("1.0");
doc.setXmlStandalone(true);
Element cancelacion = doc.createElementNS("http://cancelacfd.sat.gob.mx","Cancelacion");
cancelacion.setAttribute("RfcEmisor", rfc);
cancelacion.setAttribute("Fecha", fecha);
doc.appendChild(cancelacion);
Element folios = doc.createElementNS("http://cancelacfd.sat.gob.mx", "Folios");
cancelacion.appendChild(folios);
for (int i=0; i<uuid.length; i++) {
Element u = doc.createElementNS("http://cancelacfd.sat.gob.mx","UUID");
u.setTextContent(uuid[i]); …Run Code Online (Sandbox Code Playgroud) 我使用以下代码针对XSD文件验证XML文件。发现错误并且xmlnsXML文件中的值有效时,它将成功调用验证处理程序。无效时,不会调用验证处理程序。
private void ui_validate_Click(object sender, EventArgs e)
{
try
{
ui_output.Text = "";
XmlDocument xml_document = new XmlDocument();
xml_document.LoadXml(ui_XML.Text);
xml_document.Schemas.Add(null, XmlReader.Create(new System.IO.StringReader(ui_XSD.Text)));
xml_document.Validate(validation_handler);
}
catch (Exception ex)
{
ui_output.Text = "Exception: " + ex.Message;
}
}
private void validation_handler(object sender, ValidationEventArgs e)
{
switch (e.Severity)
{
case XmlSeverityType.Error:
ui_output.Text += "Error: " + e.Message + Environment.NewLine;
break;
case XmlSeverityType.Warning:
ui_output.Text += "Warning: " + e.Message + Environment.NewLine;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
更新 接受的答案的示例:
XmlDocument xml_document = new XmlDocument();
xml_document.Load(@"C:\temp\example.xml"); …Run Code Online (Sandbox Code Playgroud) 我尝试使用lxml.etree解析XML文件并在XML元素中查找文本。
XML文件可以是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>2002-06-01T19:20:30Z</responseDate>
<request verb="ListRecords" from="1998-01-15"
set="physics:hep"
metadataPrefix="oai_rfc1807">
http://an.oa.org/OAI-script</request>
<ListRecords>
<record>
<header>
<identifier>oai:arXiv.org:hep-th/9901001</identifier>
<datestamp>1999-12-25</datestamp>
<setSpec>physics:hep</setSpec>
<setSpec>math</setSpec>
</header>
<metadata>
<rfc1807 xmlns=
"http://info.internet.isi.edu:80/in-notes/rfc/files/rfc1807.txt"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://info.internet.isi.edu:80/in-notes/rfc/files/rfc1807.txt
http://www.openarchives.org/OAI/1.1/rfc1807.xsd">
<bib-version>v2</bib-version>
<id>hep-th/9901001</id>
<entry>January 1, 1999</entry>
<title>Investigations of Radioactivity</title>
<author>Ernest Rutherford</author>
<date>March 30, 1999</date>
</rfc1807>
</metadata>
<about>
<oai_dc:dc
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:publisher>Los Alamos arXiv</dc:publisher>
<dc:rights>Metadata may be used without restrictions as long as
the oai identifier remains attached to it.</dc:rights>
</oai_dc:dc>
</about>
</record>
<record>
<header status="deleted"> …Run Code Online (Sandbox Code Playgroud) 我正在编写有关编写自定义spring命名空间处理程序的教程:http: //static.springsource.org/spring/docs/2.5.x/reference/extensible-xml.html
一切都工作得很好,直到我到B.5节注册新的处理程序和模式.
我尝试将spring.handlers和spring.schemas放入我的项目中 - 没有用
我能够找到文件| 设置| Schema和DTD,它确实在编辑器中启用了自动完成,但处理程序仍未注册.这也没有转换为spring.schemas文件中的条目.
简而言之,有人可以解释如何在intelliJ 11.1.2中执行以下操作吗?
a)配置它以识别新的模式和命名空间处理程序b)在构建工件时将正确的信息放入META-INF/spring.handlers和spring.schemas文件中?
任何帮助将不胜感激.
我有这样的事情:
$x = simplexml_load_file('myxml.xml');
[...]
foreach($x->y->z[0]->w->k as $k){
[...]
}
Run Code Online (Sandbox Code Playgroud)
我的XML文件类似于:
<x>
<y>
<z>
<w>
<k prefix:name="value">
[...]
</k>
</w>
[...]
</z>
[...]
</y>
[...]
</x>
Run Code Online (Sandbox Code Playgroud)
现在,我想访问我的k元素的属性.在我的foreach中,我有红色,我可以使用它来访问它:
$k['prefix:name']
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我做错了什么?
我在我的k元素中添加了一个假属性并且它有效,我认为问题是我尝试访问的属性位于不同的命名空间中:
<k xsi:type="value">
[...]
</k>
Run Code Online (Sandbox Code Playgroud) 在部署到本地服务器后,是否可以将JSF应用程序配置为在没有Internet访问的情况下运行?
xmlns="http://www.w3.org/1999/xhtml
xmlns:h="http://xmlns.jcp.org/jsf/html
Run Code Online (Sandbox Code Playgroud)
以上XML命名空间会在部署后出现任何问题吗?
我试过很多答案#1解决我的问题,像这一个.但似乎没有一个在我的XML文档上工作.
这是我的XML
<w:wordDocument xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
w:macrosPresent="no"
w:embeddedObjPresent="no"
w:ocxPresent="no"
xml:space="preserve">
<w:ignoreSubtree
w:val="http://schemas.microsoft.com/office/word/2003/wordml/sp2" />
...
<w:body>
<w:p
wsp:rsidR="009D1011"
wsp:rsidRDefault="001D7CCD">
...
Run Code Online (Sandbox Code Playgroud)
我正在尝试找到<w:p>具有命名空间的节点.
这是我最近的尝试:
string xmlNamespace = String.Empty;
XmlNamespaceManager nsmgr;
//xml is my XMLDocument
XmlNodeList nodeInfo = xml.GetElementsByTagName("w:wordDocument");
XmlAttributeCollection att = nodeInfo[0].Attributes;
xmlNamespace = Convert.ToString(nodeInfo[0].Attributes["xmlns"].Value);
nsmgr = new XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("w", xmlNamespace);
XmlNode myNode = xml.DocumentElement.SelectSingleNode("w:wordDocument/w:body", nsmgr);
Run Code Online (Sandbox Code Playgroud)
但myNode总是返回null
谁能告诉我我做错了什么?