我想知道为什么没有Web浏览器支持XHTML的XInclude标准.
这个标准存在了将近五年,我认为它对网络非常有用.例如,您可以XInclude网站的静态部分,这样浏览器只需要下载用户浏览网站时已更改的部分.此外(但我可能错了)与SVG或MathML等标准相比,这似乎并不是很难支持.
(抱歉这个问题没有真正的答案,我不介意它是否关闭)
我在我的应用程序中看到,在我的解析XML文件中包含xinclude在我的Java XSLT转换中不起作用.
但是,虽然我这样做:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setXIncludeAware(true);
Run Code Online (Sandbox Code Playgroud)
我不是专门设置变压器工厂为System.getProperty("javax.xml.transform.TransformerFactory")返回"null".
我的问题:默认的Java(1.6或6)是否支持xinclude,还是我必须添加替代的XSLT解析器,例如Apache Xerces?
我想合并2个具有相同结构的XML文件来制作一个.例如;
Test1.xml
<?xml version="1.0" encoding="UTF-8"?>
<ns:Root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns="urn:TestNamespace"
xsi:schemaLocation="urn:Test.Namespace Test1.xsd"
>
<ns:element1 id="001">
<ns:element2 id="001.1" order="1">
<ns:element3 id="001.1.1" />
</ns:element2>
<ns:element2 id="001.2" order="2">
<ns:element3 id="001.1.2" />
</ns:element2>
</ns:element1>
</ns:Root>
Run Code Online (Sandbox Code Playgroud)
和Test2.xml
<?xml version="1.0" encoding="UTF-8"?>
<ns:Root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns="urn:TestNamespace"
xsi:schemaLocation="urn:Test.Namespace Test1.xsd"
>
<ns:element1 id="999">
<ns:element2 id="999.1" order="1">
<ns:element3 id="999.1.1" />
</ns:element2>
</ns:element1>
</ns:Root>
Run Code Online (Sandbox Code Playgroud)
创造
TestOutput.xml
<?xml version="1.0" encoding="UTF-8"?>
<ns:Root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns="urn:TestNamespace"
xsi:schemaLocation="urn:Test.Namespace Test1.xsd"
>
<ns:element1 id="001">
<ns:element2 id="001.1" order="1">
<ns:element3 id="001.1.1" />
</ns:element2>
<ns:element2 id="001.2" order="2">
<ns:element3 id="001.1.2" />
</ns:element2>
</ns:element1>
<ns:element1 …Run Code Online (Sandbox Code Playgroud) 如果我没有用Google搜索到Oblivion,我就不会在这里.我有以下问题:我有一个XML Schema,3个单个XML文档和一个XML文档来链接所有其他3.我遇到以下错误,我不明白为什么.
E [Xerces] cvc-complex-type.3.2.2:属性'xml:base'不允许出现在元素'SoftwareRequirementsDocument'中.
我已经阅读了谷歌的一些论坛帖子,其中有类似问题的人,但他们的修复都不会对我有所帮助.我将发布我的Schema,1个要连接的XML文档,以及带有XInclude的XML文档.我将发布每个文档的开头,因为这是需要的.
这是NotionalSchema2.xsd:
<xsd:element name="ProjectLifecycleDocuments" type="ProjectLifecycleDocumentsType"/>
<xsd:complexType name="ProjectLifecycleDocumentsType">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="Team"/>
<xsd:element ref="SoftwareRequirementsDocument"/>
<xsd:element ref="UseCaseDocument"/>
<xsd:element ref="TestCaseDocument"/>
</xsd:choice>
<xsd:attribute name="id" use="required" type="xsd:ID"/>
</xsd:complexType>
<xsd:element name="SoftwareRequirementsDocument" type="SoftwareRequirementsDocumentType"/>
<xsd:complexType name="SoftwareRequirementsDocumentType">
<xsd:sequence>
<xsd:element ref="Section" maxOccurs="unbounded"/>
<!-- Other global elements to be referenced here. -->
</xsd:sequence>
<xsd:attribute name="projectName" use="required" type="xsd:string"/>
<!--<xsd:attribute name="id" use="required" type="xsd:ID"/>-->
</xsd:complexType>
Run Code Online (Sandbox Code Playgroud)
这是我的NotionalSRS2.xml:
<SoftwareRequirementsDocument projectName="Lifecycle Documents with Requirements
Tracking" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="NotionalSchema2.xsd"
xmlns:xx="http://apache.org/xml/features/xinclude/fixup-base-uris">
<Section id="RQ1.0">
<Title>Introduction</Title>
<Para>The Software Requirements Specification details the extent of NUWC’s Lifecycle …Run Code Online (Sandbox Code Playgroud) 我正在 Python 中使用 lxml 开发一个简单的 xml 日志文件类。
到目前为止,我的方法是使用两个文件。格式良好的 XML 文件,其中包含第二个文件(XML 片段)。我正在使用 xi:include 元素。这样,只需将<event>元素附加到文件末尾即可有效地更新 XML 片段。
格式良好的 XML 文件(“logfile.xml”)如下所示:
<?xml version="1.0"?>
<logfile>
<event xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="events.xml"/>
</event>
</logfile>
Run Code Online (Sandbox Code Playgroud)
xml 片段('events.xml')如下所示:
<event>
<data></data>
</event>
<event>
<data></data>
</event>
<event>
<data></data>
</event>
Run Code Online (Sandbox Code Playgroud)
我的目标是最终达到:
<?xml version="1.0"?>
<logfile>
<event>
<data></data>
</event>
<event>
<data></data>
</event>
<event>
<data></data>
</event>
</logfile>
Run Code Online (Sandbox Code Playgroud)
在 python 中,我使用 xinclude 方法来处理格式良好的 XML 文件(“logfile.xml”)中的 xi:include 元素。这有效,但仅当有一个<event>元素是 XML 片段('events.xml')时
我的Python代码:
tree = etree.parse('logfile.xml')
tree.xinclude()
root = tree.getroot()
print etree.tostring(self.logfileNode, pretty_print=True, …Run Code Online (Sandbox Code Playgroud) 我有这个XML文件:
<?xml version="1.0"?>
<xi:include href="http://www.w3schools.com/dom/books.xml"
xmlns:xi="http://www.w3.org/2003/XInclude"/>
Run Code Online (Sandbox Code Playgroud)
我希望它在http://www.w3schools.com/dom/books.xml处理时应该导致引用的远程XML文件.
为此我创建了这个XSL文件:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml"/>
<xsl:template match="*">
<xsl:copy-of select="//book/title"/>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
在XSL转换之后,我希望从引用的XML文件中获取带有标题节点的XML输出.
然而它没有发生,转换只是产生了一个空文件.我怀疑XInclude没有执行指令.
那么如果可能的话,如何在Xincluded XML文件上应用XSLT?
我正在尝试使用XInclude创建一个组合的xml文档,以便通过JAXB进行解组.
这是我的解组代码:
@Override
public T readFromReader(final Reader reader) throws Exception {
final Unmarshaller unmarshaller = createUnmarshaller();
final SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setXIncludeAware(true);
spf.setNamespaceAware(true);
//spf.setValidating(true);
final XMLReader xr = spf.newSAXParser().getXMLReader();
final SAXSource source = new SAXSource( xr, new InputSource(reader) );
try {
final T object = (T) unmarshaller.unmarshal(source);
postReadSetup(object);
return object;
} catch (final Exception e) {
throw new RuntimeException("Cannot parse XML: Additional information is attached. Please ensure your XML is valid.", e);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的主要xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<tag1 …Run Code Online (Sandbox Code Playgroud) 我有一个包含 2 个 'sub_x.xml' 文件的 'main.xml' 文件。包含行使用“xpointer”来仅指向/包含包含 xml 的特定标签。当我使用 ElementTree 来确定这是否正常工作时,它表明包含了整个“sub”xml 文件,而不仅仅是我想要的标签。我不确定我是否错误地使用了 xpointer 或者 ElementTree 或 ElementInclude 不支持这一点。以下是文件:
------'main.xml'--------
`<?xml version='1.0' encoding='utf-8'?>
<ModelInfo xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="sub_1.xml" xpointer="xpointer(//ModelInfo/Model)" parse="xml" />
<xi:include href="sub_2.xml" xpointer="xpointer(//ModelInfo/Model)" parse="xml" />
</ModelInfo>`
Run Code Online (Sandbox Code Playgroud)
-------'sub_1.xml'------
`<?xml version="1.0" ?>
<ModelInfo>
<Model ModelName="glow">
<Variables>
<Variable Alias="glow_val" Input="False" Output="True" />
</Variables>
</Model>
</ModelInfo>`
Run Code Online (Sandbox Code Playgroud)
-------'sub_2.xml'------
`<?xml version='1.0' encoding='utf-8'?>
<ModelInfo>
<Model ModelName="sirpwr_b_supply8v1">
<Variables>
<Variable Alias="sirpwr_a_supplyecu_Snsr8vIstat" Input="True" Output="False" />
</Variables>
</Model>
</ModelInfo>`
Run Code Online (Sandbox Code Playgroud)
我希望 'main.xml' 在 ElementTree 中显示为:
`<?xml version='1.0' encoding='utf-8'?>
<ModelInfo xmlns:xi="http://www.w3.org/2001/XInclude">
<Model ModelName="glow">
<Variables> …Run Code Online (Sandbox Code Playgroud) 我正在尝试解组包含<xi:include>标签的 xml 文档。但是 SAXParser 不允许这样做,即使我特别告诉 SAXParserFactory 允许它。
Java代码:
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setXIncludeaware(true);
spf.setNamespaceAwere(true);
spf.setFeature("http://apache.org/xml/features/xinclude", true);
spf.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", true);
XMLReader xr = spf.newSAXParser().getXMLReader();
SAXSource source = new SAXSource(xr, new InputSource(inputStream));
JAXBElement<MyClass> el = unmarshaller.unmarshal(source, MyClass.class);
Run Code Online (Sandbox Code Playgroud)
要读取的 XML 文档
<?xml version="1.0" encoding="UTF-8"?>
<extension xmlns="http://www.example.com/test" xmlns:ext="http://www.example.com/test" xmlns:xi="http://www.w3.org/2003/XInclude">
<visibility>
<resourceConstraints>
<resourceConstraint ext:resourceId="resourceOne">
<role ext:show="true">AdminUsers</role>
</resourceConstraint>
<resourceConstraint ext:resourceId="resourceTwo">
<role ext:show="true">AdminUsers</role>
</resourceConstraint>
</resourceConstraints>
<xi:include href="extraContent.xml" />
</visibility>
</extension>
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到这个异常:
org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 50; cvc-complex-type.2.4.a: Invalid content was found starting with element 'xi:include'. One …Run Code Online (Sandbox Code Playgroud) 基于如何使用xpointer与Xinclude引用元素 ...
当命名空间urn包含多个冒号时,我遇到了包括使用xpointer的嵌套元素的问题.
Test1.xml
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns="urn:some:namespace">
<element1 id="001">
<element2 id="001.1" order="1">
<element3 id="001.1.1"/>
</element2>
<element2 id="001.2" order="2">
<lement3 id="001.1.2"/>
</element2>
</element1>
</Root>
Run Code Online (Sandbox Code Playgroud)
Test2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<element1 id="999">
<element2 id="999.1" order="1">
<element3 id="999.1.1"/>
</element2>
</element1>
</Root>
Run Code Online (Sandbox Code Playgroud)
的merge.xml
<?xml version="1.0"?>
<Root xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="Test1.xml" xpointer="xmlns(ns=urn:some:namespace)xpointer(/ns:Root/ns:element1)" parse="xml" />
<xi:include href="Test2.xml" xpointer="xpointer(//Root/element1)" parse="xml" />
</Root>
Run Code Online (Sandbox Code Playgroud)
命令:
xmllint --pretty 1 --xinclude Merge.xml
错误
Merge.xml:5: element include: XInclude error : XPointer evaluation failed: #xmlns(ns=urn:some:namespace)xpointer(/ns:Root/ns:element1)
Merge.xml:5: element include: XInclude error : …Run Code Online (Sandbox Code Playgroud)