我需要获取一个现有的xml文件,并修改一些属性并将文件写回.
我正在考虑使用libxml2来完成这项工作.应用程序是在Linux上运行的C/C++.
事实上,libxml2似乎包括厨房水槽的几种变体,以及便携式洗手间,淋浴和通过相同管道连接的各种其他东西.有不同的解析器可用,以及不同的处理方式.对于之前没有使用过libxml2的人来说,这有点令人生畏.
我应该看一下哪个例子,最后,我的输出.xml与原始输入文件相同,加上我所做的更改?到目前为止,我一直在使用libxml2的tree1.c,tree2.c和reader1.c示例,但只有这些输出xml不会在任何地方接近相同.
<td></td><td>foo</td>
我想返回['', 'foo']但是libxml的xpath //td/text()只返回['foo'].如何找到空标签''而不是(不匹配)?
早上好,
我正在尝试使用python模块安装libxml2.我尝试过以下方法:
brew install --with-python libxml2
==> Downloading ftp://xmlsoft.org/libxml2/libxml2-2.8.0.tar.gz
Already downloaded: /Users/brandon/Library/Caches/Homebrew/libxml2-2.8.0.tar.gz
==> ./configure --prefix=/usr/local/Cellar/libxml2/2.8.0 --without-python
Run Code Online (Sandbox Code Playgroud)
正如你所看到的......即使使用--with-python标志,它仍然在没有python的情况下配置源代码!
在安装结束时,自制软件说:
Generally there are no consequences of this for you.
If you build your own software and it requires this formula, you'll need
to add its lib & include paths to your build variables:
LDFLAGS -L/usr/local/Cellar/libxml2/2.8.0/lib
CPPFLAGS -I/usr/local/Cellar/libxml2/2.8.0/include
Run Code Online (Sandbox Code Playgroud)
当我尝试安装gnome-doc-utils包时:
Gnome-doc-utils requires libxml2 to be compiled
with the python modules enabled, to do so:
$ brew install libxml2 --with-python
Run Code Online (Sandbox Code Playgroud)
显然我再试一次......
?? brew install libxml2 …Run Code Online (Sandbox Code Playgroud) 什么是将大量XML从RESTful服务异步提取到Core Data存储中,以及从这个存储中快速填充的好方法UITableView?
我正在考虑使用libxml2的xmlParseChunk()函数来解析传入XML的块,并在节点进入时将节点及其子节点转换为相关的托管对象.
在将这些XML节点转换为托管对象的同时,我想UITableView依次生成行.比如说,一次50行.这是现实的吗?
根据您的经验,您如何完成此任务,以维护性能并处理数千行?是否有不同的,更简单的方法可以运行得更好或更好?
请有人向我展示一个使用libxml解析一些HTML的简单示例.
#import <libxml2/libxml/HTMLparser.h>
NSString *html = @"<ul>"
"<li><input type=\"image\" name=\"input1\" value=\"string1value\" /></li>"
"<li><input type=\"image\" name=\"input2\" value=\"string2value\" /></li>"
"</ul>"
"<span class=\"spantext\"><b>Hello World 1</b></span>"
"<span class=\"spantext\"><b>Hello World 2</b></span>";
Run Code Online (Sandbox Code Playgroud)
1)假设我想解析name = input2的输入值.
应该输出"string2value".
2)假设我想解析class = spantext的每个span标记的内部内容.
应输出:"Hello World 1"和"Hello World 2".
我有一个源文件,我可以通过终端使用
gcc source.c -I/usr/include/libxml2 -lxml2 -o output
Run Code Online (Sandbox Code Playgroud)
但是当我#include的源文件,其中包含了libxml的源文件,编译器会抱怨的libxml/xmlmemory.h:,libxml/parser.h:,libxml/xpath.h不能被发现:没有这样的文件或目录.
我试图使用XPath 2.0EXP //span/string(.)中libxml2,但它不工作.
所以,我的问题是:libxml2支持XPath 2.0与否?
debugging objective-c libxml2 interface-implementation xpath-2.0
根据lxml文档"DTD是根据解析文档的DOCTYPE自动检索的.您所要做的就是使用启用了DTD验证的解析器."
http://lxml.de/validation.html#validation-at-parse-time
但是,如果要对XML架构进行验证,则需要显式引用一个.
我想知道为什么这是,并想知道是否有一个库或函数可以做到这一点.或者甚至解释如何让自己发生这种情况.问题是似乎有很多方法可以引用XSD,我需要支持所有这些方法.
验证不是问题.问题是如何确定要验证的模式.理想情况下,这也可以处理内联模式.
更新:
这是一个例子.
simpletest.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="name" type="xs:string"/>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
simpletest.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<name xmlns="http://www.example.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org simpletest.xsd">foo</name>
Run Code Online (Sandbox Code Playgroud)
我想做类似以下的事情:
>>> parser = etree.XMLParser(xsd_validation=True)
>>> tree = etree.parse("simpletest.xml", parser)
Run Code Online (Sandbox Code Playgroud) 可能重复:
ASIHTTPRequest; 安装问题
我一步一步地遵循了设置教程,但是我收到了这个错误:'libxml/HTMLparser.h' file not found.我还克隆了libxml库,但它不起作用.任何的想法?谢谢!
我创建了一个像下面的xml
<Request>
<RequestType>Logon</RequestType>
<MobileId>23424</MobileId>
<Password>123456Gg</Password>
</Request>
Run Code Online (Sandbox Code Playgroud)
我的xsd文件就像下面的代码
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Request" type="RequestType"/>
<xsd:complexType name="RequestType">
<xsd:sequence>
<xsd:element name="RequestType">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Logon"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="MobileId" >
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="0" />
<xsd:maxLength value="10" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Password">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="0"/>
<xsd:maxLength value="255"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)
我使用PHP'S DOMDocument的schemaValidate函数来验证xml对xsd,并给出以下错误
Fatal Error 4: Start tag expected, '<' not found on line 5
Error 1872: The document has …Run Code Online (Sandbox Code Playgroud)