简体   繁体   English

尝试在 eXist-db 中提取 TEI xml 时未获取文本节点

[英]Not getting text nodes while trying to extract TEI xml in eXist-db

I have an XML file and want to extract text in HTML, but it's empty when I do it.我有一个 XML 文件,想提取 HTML 中的文本,但是当我这样做时它是空的。 I am trying to get the text from the tag and it works just fine when I delete the beginning of the XML code and start the file with tag.我试图从标签中获取文本,当我删除 XML 代码的开头并用标签启动文件时,它工作得很好。 Here is a beginning of an XML file:这是 XML 文件的开头:

<TEI xmlns="http://www.tei-c.org/ns/1.0" xmlns:vg="http://www.vangoghletters.org/ns/">
    <teiHeader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <fileDesc>
            <titleStmt>
                <title>book title</title>
            </titleStmt>
            <publicationStmt>
                <publisher>
                    <name> name of the publisher </name>
                </publisher>
                <date type="first" when="2021">2021</date>
                <availability status="restricted">
                    <licence target="http://creativecommons.org/licenses/by-nc-sa/4.0/ https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode">
                        <p>Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) </p>
                    </licence>
                </availability>
                <ptr target="http://vangoghletters.org/orig/let001"/>
            </publicationStmt>
            <sourceDesc>
                <vg:letDesc>
                    <vg:letIdentifier>
                        <idno type="jlb">001</idno>
                        <idno type="collectedletters">1</idno>
                        <idno type="brieven1990">001</idno>
                    </vg:letIdentifier>

                    <vg:letContents>
                        <p>book name, chapter</p>
                    </vg:letContents>
                    <note type="sourceStatus" xml:id="sourceStatus">
                        <p> handwriting </p>
                    </note>
                    <note type="additionalDetail" xml:id="additionalDetail">
                        <p> some text</p>
                    </note>
                </vg:letDesc>
            </sourceDesc>
        </fileDesc>
    </teiHeader>
    
    <text xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <body>
            <div type="original" xml:lang="ka">
            
                <pb f="1r" n="1" xml:id="pb-orig-1r-1" facs="#zone-pb-1r-1"/>
                <lb n="2" xml:id="l-1"/>
                <ab>There <rs type="pers" key="320"><supplied reason="lost">ეს</supplied>[7125.1]არისთა</rs>,
                    <rs type="pers" key="1643">მეფისა </rs>
                    
                    <rs type="pers" key="838">ასუ<supplied reason="lost">რასტა</supplied>ნისათა</rs>,
                    ...

Here is my XQuery code:这是我的 XQuery 代码:

declare function app:text_orig($node as node(), $model as map(*))
{
    for $resource in collection('/db/apps/oshki/data')
        for $i in $resource//div[@type="original"]/ab//text()
            return
            <p>  {$i} </p>
};

Any idea why this happens?知道为什么会这样吗?

Your root-element <TEI is in a namespace with the uri: "http://www.tei-c.org/ns/1.0" and therefore your div is in this case also in that namespace.您的根元素<TEI位于具有 uri: "http://www.tei-c.org/ns/1.0" 的命名空间中,因此在这种情况下,您的 div 也在该命名空间中。 See ie this answer on how to use exist-db with namespaces请参阅即有关如何将exist-db 与命名空间一起使用的答案

Elements in the TEI vocabulary all come in an XML namespace, as indicated by the xmlns attribute - a reserved attribute used for declaring XML namespace bindings: TEI 词汇表中的元素都来自一个 XML 命名空间,如xmlns属性所示 - 一个用于声明 XML 命名空间绑定的保留属性:

<TEI xmlns="http://www.tei-c.org/ns/1.0">

An XML-aware application such as eXist-db has various facilities for querying namespaced XML.诸如 eXist-db 之类的 XML 感知应用程序具有用于查询命名空间 XML 的各种工具。 Most commonly in XQuery, you will add a "namespace declaration" to your query's prolog, which binds the namespace URI to a namespace prefix:在 XQuery 中,最常见的是将“命名空间声明”添加到查询的序言中,它将命名空间 URI 绑定到命名空间前缀:

declare namespace tei="http://www.tei-c.org/ns/1.0";

Then you can use the tei namespace prefix in your query:然后您可以在查询中使用tei命名空间前缀:

//tei:div[@type="original"]/tei:ab

When you removed the <TEI> root element, you also stripped off the namespace binding on the inner elements.当您删除<TEI>根元素时,您还剥离了内部元素上的命名空间绑定。 They appeared to eXist as if they were in the "empty" namespace - the default element namespace.它们似乎存在于“空”命名空间中——默认元素命名空间。 This is why your query worked without specifying namespaces in that case.这就是为什么在这种情况下您的查询没有指定命名空间就可以工作的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM