从 XML xmlstarlet 获取属性

Get attribute from XML xmlstarlet

我正在使用 xmlstarlet 库,我正在尝试从 sh 文件访问 xml attribures。

AMOUNT= `cat $XML_FILE | xmlstarlet sel -t -m "//unjFeed/unjEntry/unjAmount" -o " " -v "."`

我得到的结果是空的。有什么建议吗?我是 bash 脚本编写的初学者

我在这里查看了文档 http://xmlstar.sourceforge.net/doc/UG/ch04.html.

XML 文件

<unjFeed>
      <unjEntry jackpotId="197993441" jackpotName="Power Jackpot">
        <unjAmount curency="EUR" amount="50035.12"/>
        <games>
          <game id="558" name="Tycoons NJP Android"/>
          <game id="559" name="Tycoons NJP Windows Phone"/>
          <game id="556" name="Tycoons NJP"/>
          <game id="557" name="Tycoons NJP Mobile"/>
          <game id="555" name="Glam Life NJP"/>
          <game id="567" name="At The Copa NJP Windows Phone"/>
          <game id="566" name="At The Copa NJP Android"/>
          <game id="565" name="At The Copa NJP Mobile"/>
          <game id="564" name="At The Copa NJP"/>
          <game id="563" name="Treasure Room NJP"/>
          <game id="562" name="The Ghouls NJP"/>
          <game id="561" name="Pharaoh King NJP"/>
          <game id="560" name="Jackpot Jamba NJP"/>
          <game id="575" name="Greedy Goblins NJP Windows Phone"/>
          <game id="574" name="Greedy Goblins NJP Android"/>
          <game id="573" name="Greedy Goblins NJP Mobile"/>
          <game id="572" name="Greedy Goblins NJP"/>
          <game id="571" name="Mr Vegas NJP Windows Phone"/>
          <game id="570" name="Mr Vegas NJP Android"/>
          <game id="569" name="Mr Vegas NJP Mobile"/>
          <game id="568" name="Mr Vegas NJP"/>
          <game id="576" name="Slots Angels NJP"/>
          <game id="580" name="Good Girl, Bad Girl NJP"/>
          <game id="581" name="Good Girl, Bad Girl NJP Mobile"/>
          <game id="582" name="Good Girl, Bad Girl NJP Android"/>
          <game id="583" name="Good Girl, Bad Girl NJP Windows Phone"/>
        </games>
      </unjEntry>
    </unjFeed>

XSD 文件

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="unjFeed">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="unjEntry">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="unjAmount">
                <xs:complexType>
                  <xs:simpleContent>
                    <xs:extension base="xs:string">
                      <xs:attribute type="xs:string" name="curency"/>
                      <xs:attribute type="xs:float" name="amount"/>
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
              <xs:element name="games">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="game" maxOccurs="unbounded" minOccurs="0">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:string">
                            <xs:attribute type="xs:short" name="id" use="optional"/>
                            <xs:attribute type="xs:string" name="name" use="optional"/>
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute type="xs:int" name="jackpotId"/>
            <xs:attribute type="xs:string" name="jackpotName"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

提前致谢

cat jp.bak.xml | xmlstarlet sel -t -v  "/unjFeed/unjEntry/unjAmount/@amount"

"/unjFeed/unjEntry/unjAmount/@amount" 是访问调用amount的属性

作为文件夹结构访问