문제

I've found a lot of topics on stackoverflow about xmllint and its "namespaces support" but none helped me.

Here is my xml (xsd to be precise) file:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema">
    <xsd:annotation>
        <xsd:documentation>My Text</xsd:documentation>
    </xsd:annotation>
</xsd:schema>

I want to retrieve "My Text" chain from this file so I try this:

xmllint myfile.xsd --xpath "/*[namespace-uri()='http://www.w3.org/2001/XMLSchema' and 
name()='schema']/*[namespace-uri()='http://www.w3.org/2001/XMLSchema' and
name()='annotation']/*[namespace-uri()='http://www.w3.org/2001/XMLSchema' and
name()='documentation']/text()"

but it doesn't work. I get "Segmentation Fault."

UPDATE

I have another question: What should I use to get my tag's attribute "toto" value in this file:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:toto="testAtributeValue">
    <xsd:annotation>
        <xsd:documentation>myText</xsd:documentation>
    </xsd:annotation>
</xsd:schema>

To put it another way, I want to get "testAtributeValue"

도움이 되었습니까?

해결책

Your XML it is invalid because the "xsd" prefix is not declared (which was even reported in the command output edited out in the second .version of the question).

You want xmlns:xsd= not xmlns=.

Also name() returns a QName. You want to use local-name() to match local names.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top