如何在Java中使用JiBX解析spdx文件

如何在Java中使用JiBX解析spdx文件,java,parsing,jibx,Java,Parsing,Jibx,我试图在Java中使用JiBX解析spdx文件。我只想解析一些元素,而不是文件中的所有元素,而不是以有序的方式,并且一些元素会重复。我要分析的一些元素是:、或。 我遇到的问题是,解析后,对象的属性为null。对象本身不是空的 你能帮帮我吗 绑定XML文件是: <binding> <mapping name="RDF" class="com.transfer.SpdxTransferObject" ordered="false" flexible="true">

我试图在Java中使用JiBX解析spdx文件。我只想解析一些元素,而不是文件中的所有元素,而不是以有序的方式,并且一些元素会重复。我要分析的一些元素是:。 我遇到的问题是,解析后,对象的属性为null。对象本身不是空的

你能帮帮我吗

绑定XML文件是:

<binding>
    <mapping name="RDF" class="com.transfer.SpdxTransferObject" ordered="false" flexible="true">
        <namespace uri="http://www.w3.org/1999/02/22-rdf-syntax-ns#" prefix="rdf" default="all"/>
        <namespace uri="http://usefulinc.com/ns/doap#" prefix="j.0" />
        <namespace uri ="http://www.w3.org/2000/01/rdf-schema#" prefix="rdfs" />
        <namespace uri="http://spdx.org/rdf/terms#" prefix="noPrefix"/>
            <value name="creator" field="mCreator" get-method="getCreator"  set-method="setCreator" default="none"/>
</mapping>
Java代码是:

public class ParseSpdxFile
{
    /** Our logger */
    private static Log sLog = LoggerFactory.create();

    public static SpdxTransferObject parseFromFile(final File pFile) throws ValidationException
    {
        sLog.debug("Parsing the Spdx file");
        SpdxTO data = null;
        JiBXFileHandler handler;
        try
        {
            handler = new JiBXFileHandler(BindingDirectory.getFactory(SpdxTransferObject.class));
            data = (SpdxTransferObject) handler.loadFromXML(pFile);
        }
        catch (JiBXException e)
        {
            throw new ValidationException(e);
        }
        catch (Exception e)
        {
            throw new ValidationException(e);
        }
        return data;
    }
}

public class JiBXFileHandler
{
    private final IBindingFactory mBfact;

    public JiBXFileHandler(final IBindingFactory pBfact)
    {
        mBfact = pBfact;
    }

    public Object loadFromXML(final File pFile) throws Exception
    {

        FileInputStream in = null;
        try
        {
            IUnmarshallingContext uctx = mBfact.createUnmarshallingContext();
            in = new FileInputStream(pFile);
            return uctx.unmarshalDocument(in, null);
        }
        finally
        {
            IOUtils.closeQuietly(in);
        }
    }
}
spdx文件如下所示:

<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:j.0="http://usefulinc.com/ns/doap#"
  xmlns="http://spdx.org/rdf/terms#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <SpdxDocument rdf:about="http://www.spdx.org/tools#SPDXANALYSIS">
    <reviewed>
      <Review>
        <rdfs:comment>This is just an example.</rdfs:comment>
        <reviewDate>2010-02-10T00:00:00Z</reviewDate>
        <reviewer>Person: Joe Reviewer</reviewer>
      </Review>
    </reviewed>
    <hasExtractedLicensingInfo>
      <ExtractedLicensingInfo rdf:nodeID="A0">
        <licenseText>license text</licenseText>
        <licenseId>LicenseRef-3</licenseId>
      </ExtractedLicensingInfo>
    </hasExtractedLicensingInfo>
    <specVersion>SPDX-0.8</specVersion>
    <describesPackage>
      <Package rdf:about="http://www.spdx.org/tools#SPDXANALYSIS?package">
        <licenseDeclared>
          <ConjunctiveLicenseSet>
            <member>
              <License rdf:about="http://spdx.org/licenses/MPL-1.1">
                <licenseId>MPL-1.1</licenseId>
              </License>
            </member>
            <member rdf:nodeID="A0"/>
            <member>
              <ExtractedLicensingInfo rdf:nodeID="A1">
                <licenseText>License text 2</licenseText>
                <licenseId>LicenseRef-2</licenseId>
              </ExtractedLicensingInfo>
            </member>
            <member>
              <ExtractedLicensingInfo rdf:nodeID="A2">
                <licenseText>license text 3</licenseText>
                <licenseId>LicenseRef-4</licenseId>
              </ExtractedLicensingInfo>
            </member>
            <member>
              <ExtractedLicensingInfo rdf:nodeID="A3">
                <licenseText>licence text 4</licenseText>
                <licenseId>LicenseRef-1</licenseId>
              </ExtractedLicensingInfo>
            </member>
            <member>
              <License rdf:about="http://spdx.org/licenses/Apache-2">
                <licenseId>Apache-2</licenseId>
              </License>
            </member>
          </ConjunctiveLicenseSet>
        </licenseDeclared>
        <packageDownloadLocation>http://www.spdx.org/tools</packageDownloadLocation>
        <hasFile>
          <File>
            <copyrightText>Copyright 2010, 2011</copyrightText>
            <licenseComments></licenseComments>
            <licenseInfoInFile rdf:resource="http://spdx.org/licenses/Apache-2"/>
            <licenseConcluded rdf:resource="http://spdx.org/licenses/Apache-2"/>
            <fileType>SOURCE</fileType>
            <checksum>
              <Checksum>
                <checksumValue>2fd4e1c67a2d28fced849ee1bb76e7391b93eb12</checksumValue>
                <algorithm>SHA1</algorithm>
              </Checksum>
            </checksum>
            <fileName>src/org/spdx/parser/Project.java</fileName>
          </File>
        </hasFile>
        <licenseInfoFromFiles rdf:nodeID="A3"/>
        <checksum>
          <Checksum>
            <checksumValue>2fd4e1c67a2d28fced849ee1bb76e7391b93eb12</checksumValue>
            <algorithm>SHA1</algorithm>
          </Checksum>
        </checksum>
        <sourceInfo>Version 1.0 of the SPDX Translator application</sourceInfo>
        <packageVerificationCode>
          <PackageVerificationCode>
            <packageVerificationCodeValue>4e3211c67a2d28fced849ee1bb76e7391b93feba</packageVerificationCodeValue>
            <packageVerificationCodeExcludedFile>SpdxTranslatorSpdx.txt</packageVerificationCodeExcludedFile>
            <packageVerificationCodeExcludedFile>SpdxTranslatorSpdx.rdf</packageVerificationCodeExcludedFile>
          </PackageVerificationCode>
        </packageVerificationCode>
        <packageFileName>spdxtranslator-1.0.zip</packageFileName>
        <description>This utility..</description>
        <licenseInfoFromFiles rdf:nodeID="A0"/>
        <hasFile>
          <File>
            <artifactOf>
              <j.0:Project>
                <j.0:homepage>http://www.openjena.org/</j.0:homepage>
                <j.0:name>Jena</j.0:name>
              </j.0:Project>
            </artifactOf>
            <copyrightText>(c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 jena</copyrightText>
            <licenseComments></licenseComments>
            <licenseInfoInFile rdf:nodeID="A3"/>
            <licenseConcluded rdf:nodeID="A3"/>
            <fileType>ARCHIVE</fileType>
            <checksum>
              <Checksum>
                <checksumValue>76e739c67a2d28fced849ee1bb76e7391b93eb12</checksumValue>
                <algorithm>SHA1</algorithm>
              </Checksum>
            </checksum>
            <fileName>Jenna-2.6.3/jena-2.6.3-sources.jar</fileName>
          </File>
        </hasFile>
        <name>SPDX Translator</name>
        <licenseInfoFromFiles rdf:nodeID="A1"/>
        <licenseInfoFromFiles rdf:nodeID="A2"/>
        <hasFile>
          <File>
            <artifactOf>
              <j.0:Project rdf:about="http://svn.apache.org/repos/asf/commons/proper/lang/trunk/doap_lang.rdf">
                <j.0:homepage>http://commons.apache.org/lang/</j.0:homepage>
                <j.0:name>Apache Commons Lang</j.0:name>
              </j.0:Project>
            </artifactOf>
            <copyrightText>Copyright 2001-2007</copyrightText>
            <licenseComments></licenseComments>
            <licenseInfoInFile rdf:resource="http://spdx.org/licenses/Apache-2"/>
            <licenseConcluded rdf:resource="http://spdx.org/licenses/Apache-2"/>
            <fileType>ARCHIVE</fileType>
            <checksum>
              <Checksum>
                <checksumValue>76e739c67a2d28fced849ee1bb76e7391b93eb12</checksumValue>
                <algorithm>SHA1</algorithm>
              </Checksum>
            </checksum>
            <fileName>lib/commons-lang-2.3.zip</fileName>
          </File>
        </hasFile>
        <copyrightText> Copyright 2010, 2011 Source </copyrightText>
        <licenseComments>The declared license</licenseComments>
        <licenseInfoFromFiles>
          <License rdf:about="http://spdx.org/licenses/Apache-1">
            <licenseId>Apache-1</licenseId>
          </License>
        </licenseInfoFromFiles>
        <summary>SPDX Translator utility</summary>
        <licenseInfoFromFiles rdf:resource="http://spdx.org/licenses/MPL-1.1"/>
        <licenseInfoFromFiles rdf:resource="http://spdx.org/licenses/Apache-2"/>
        <licenseConcluded>
          <ConjunctiveLicenseSet>
            <member rdf:resource="http://spdx.org/licenses/MPL-1.1"/>
            <member rdf:nodeID="A1"/>
            <member rdf:nodeID="A3"/>
            <member rdf:nodeID="A2"/>
            <member rdf:resource="http://spdx.org/licenses/Apache-2"/>
            <member rdf:nodeID="A0"/>
            <member rdf:resource="http://spdx.org/licenses/Apache-1"/>
          </ConjunctiveLicenseSet>
        </licenseConcluded>
      </Package>
    </describesPackage>
    <hasExtractedLicensingInfo rdf:nodeID="A1"/>
    <hasExtractedLicensingInfo rdf:nodeID="A3"/>
    <creationInfo>
      <CreationInfo>
        <created>2010-02-03T00:00:00Z</created>
        <rdfs:comment>This is an example of an SPDX spreadsheet format</rdfs:comment>
        <creator>Person: Steven O'Neall</creator>
        <creator>Company: Source Code Company</creator>
        <creator>Tool: SourceCode-V1.2</creator>
      </CreationInfo>
    </creationInfo>
    <hasExtractedLicensingInfo rdf:nodeID="A2"/>
    <reviewed>
      <Review>
        <rdfs:comment>Another example reviewer.</rdfs:comment>
        <reviewDate>2011-03-13T00:00:00Z</reviewDate>
        <reviewer>Person: John Reviewer</reviewer>
      </Review>
    </reviewed>
  </SpdxDocument>
</rdf:RDF>

这只是一个例子。
2010-02-10T00:00:00Z
人物:乔·评论家
许可证文本
许可证编号REF-3
SPDX-0.8
MPL-1.1
许可证文本2
许可证编号REF-2
许可证文本3
许可证编号REF-4
牌照文本4
许可证编号REF-1
Apache-2
http://www.spdx.org/tools
版权所有201012011
来源
2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
沙一
src/org/spdx/parser/Project.java
2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
沙一
SPDX转换器应用程序的1.0版
4e3211c67a2d28fced849ee1bb76e7391b93feba
SpdxTranslatorSpdx.txt
SpdxTranslatorSpdx.rdf
spdxtranslator-1.0.zip
这个实用程序。。
http://www.openjena.org/
耶拿
(c) 版权所有2000、2001、2002、2003、2004、2005、2006、2007、2008、2009 jena
档案文件
76e739c67a2d28fced849ee1bb76e7391b93eb12
沙一
Jenna-2.6.3/jena-2.6.3-sources.jar
SPDX转换器
http://commons.apache.org/lang/
阿帕奇公地酒店
版权所有2001-2007
档案文件
76e739c67a2d28fced849ee1bb76e7391b93eb12
沙一
lib/commons-lang-2.3.zip
版权所有2010年,2011年来源
声明的许可证
Apache-1
SPDX转换器实用程序
2010-02-03T00:00:00Z
这是SPDX电子表格格式的一个示例
人物:史蒂文·奥尼尔
公司:源代码公司
工具:SourceCode-V1.2
另一个例子是审稿人。
2011-03-13T00:00:00Z
人物:约翰·里沃特
<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:j.0="http://usefulinc.com/ns/doap#"
  xmlns="http://spdx.org/rdf/terms#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <SpdxDocument rdf:about="http://www.spdx.org/tools#SPDXANALYSIS">
    <reviewed>
      <Review>
        <rdfs:comment>This is just an example.</rdfs:comment>
        <reviewDate>2010-02-10T00:00:00Z</reviewDate>
        <reviewer>Person: Joe Reviewer</reviewer>
      </Review>
    </reviewed>
    <hasExtractedLicensingInfo>
      <ExtractedLicensingInfo rdf:nodeID="A0">
        <licenseText>license text</licenseText>
        <licenseId>LicenseRef-3</licenseId>
      </ExtractedLicensingInfo>
    </hasExtractedLicensingInfo>
    <specVersion>SPDX-0.8</specVersion>
    <describesPackage>
      <Package rdf:about="http://www.spdx.org/tools#SPDXANALYSIS?package">
        <licenseDeclared>
          <ConjunctiveLicenseSet>
            <member>
              <License rdf:about="http://spdx.org/licenses/MPL-1.1">
                <licenseId>MPL-1.1</licenseId>
              </License>
            </member>
            <member rdf:nodeID="A0"/>
            <member>
              <ExtractedLicensingInfo rdf:nodeID="A1">
                <licenseText>License text 2</licenseText>
                <licenseId>LicenseRef-2</licenseId>
              </ExtractedLicensingInfo>
            </member>
            <member>
              <ExtractedLicensingInfo rdf:nodeID="A2">
                <licenseText>license text 3</licenseText>
                <licenseId>LicenseRef-4</licenseId>
              </ExtractedLicensingInfo>
            </member>
            <member>
              <ExtractedLicensingInfo rdf:nodeID="A3">
                <licenseText>licence text 4</licenseText>
                <licenseId>LicenseRef-1</licenseId>
              </ExtractedLicensingInfo>
            </member>
            <member>
              <License rdf:about="http://spdx.org/licenses/Apache-2">
                <licenseId>Apache-2</licenseId>
              </License>
            </member>
          </ConjunctiveLicenseSet>
        </licenseDeclared>
        <packageDownloadLocation>http://www.spdx.org/tools</packageDownloadLocation>
        <hasFile>
          <File>
            <copyrightText>Copyright 2010, 2011</copyrightText>
            <licenseComments></licenseComments>
            <licenseInfoInFile rdf:resource="http://spdx.org/licenses/Apache-2"/>
            <licenseConcluded rdf:resource="http://spdx.org/licenses/Apache-2"/>
            <fileType>SOURCE</fileType>
            <checksum>
              <Checksum>
                <checksumValue>2fd4e1c67a2d28fced849ee1bb76e7391b93eb12</checksumValue>
                <algorithm>SHA1</algorithm>
              </Checksum>
            </checksum>
            <fileName>src/org/spdx/parser/Project.java</fileName>
          </File>
        </hasFile>
        <licenseInfoFromFiles rdf:nodeID="A3"/>
        <checksum>
          <Checksum>
            <checksumValue>2fd4e1c67a2d28fced849ee1bb76e7391b93eb12</checksumValue>
            <algorithm>SHA1</algorithm>
          </Checksum>
        </checksum>
        <sourceInfo>Version 1.0 of the SPDX Translator application</sourceInfo>
        <packageVerificationCode>
          <PackageVerificationCode>
            <packageVerificationCodeValue>4e3211c67a2d28fced849ee1bb76e7391b93feba</packageVerificationCodeValue>
            <packageVerificationCodeExcludedFile>SpdxTranslatorSpdx.txt</packageVerificationCodeExcludedFile>
            <packageVerificationCodeExcludedFile>SpdxTranslatorSpdx.rdf</packageVerificationCodeExcludedFile>
          </PackageVerificationCode>
        </packageVerificationCode>
        <packageFileName>spdxtranslator-1.0.zip</packageFileName>
        <description>This utility..</description>
        <licenseInfoFromFiles rdf:nodeID="A0"/>
        <hasFile>
          <File>
            <artifactOf>
              <j.0:Project>
                <j.0:homepage>http://www.openjena.org/</j.0:homepage>
                <j.0:name>Jena</j.0:name>
              </j.0:Project>
            </artifactOf>
            <copyrightText>(c) Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 jena</copyrightText>
            <licenseComments></licenseComments>
            <licenseInfoInFile rdf:nodeID="A3"/>
            <licenseConcluded rdf:nodeID="A3"/>
            <fileType>ARCHIVE</fileType>
            <checksum>
              <Checksum>
                <checksumValue>76e739c67a2d28fced849ee1bb76e7391b93eb12</checksumValue>
                <algorithm>SHA1</algorithm>
              </Checksum>
            </checksum>
            <fileName>Jenna-2.6.3/jena-2.6.3-sources.jar</fileName>
          </File>
        </hasFile>
        <name>SPDX Translator</name>
        <licenseInfoFromFiles rdf:nodeID="A1"/>
        <licenseInfoFromFiles rdf:nodeID="A2"/>
        <hasFile>
          <File>
            <artifactOf>
              <j.0:Project rdf:about="http://svn.apache.org/repos/asf/commons/proper/lang/trunk/doap_lang.rdf">
                <j.0:homepage>http://commons.apache.org/lang/</j.0:homepage>
                <j.0:name>Apache Commons Lang</j.0:name>
              </j.0:Project>
            </artifactOf>
            <copyrightText>Copyright 2001-2007</copyrightText>
            <licenseComments></licenseComments>
            <licenseInfoInFile rdf:resource="http://spdx.org/licenses/Apache-2"/>
            <licenseConcluded rdf:resource="http://spdx.org/licenses/Apache-2"/>
            <fileType>ARCHIVE</fileType>
            <checksum>
              <Checksum>
                <checksumValue>76e739c67a2d28fced849ee1bb76e7391b93eb12</checksumValue>
                <algorithm>SHA1</algorithm>
              </Checksum>
            </checksum>
            <fileName>lib/commons-lang-2.3.zip</fileName>
          </File>
        </hasFile>
        <copyrightText> Copyright 2010, 2011 Source </copyrightText>
        <licenseComments>The declared license</licenseComments>
        <licenseInfoFromFiles>
          <License rdf:about="http://spdx.org/licenses/Apache-1">
            <licenseId>Apache-1</licenseId>
          </License>
        </licenseInfoFromFiles>
        <summary>SPDX Translator utility</summary>
        <licenseInfoFromFiles rdf:resource="http://spdx.org/licenses/MPL-1.1"/>
        <licenseInfoFromFiles rdf:resource="http://spdx.org/licenses/Apache-2"/>
        <licenseConcluded>
          <ConjunctiveLicenseSet>
            <member rdf:resource="http://spdx.org/licenses/MPL-1.1"/>
            <member rdf:nodeID="A1"/>
            <member rdf:nodeID="A3"/>
            <member rdf:nodeID="A2"/>
            <member rdf:resource="http://spdx.org/licenses/Apache-2"/>
            <member rdf:nodeID="A0"/>
            <member rdf:resource="http://spdx.org/licenses/Apache-1"/>
          </ConjunctiveLicenseSet>
        </licenseConcluded>
      </Package>
    </describesPackage>
    <hasExtractedLicensingInfo rdf:nodeID="A1"/>
    <hasExtractedLicensingInfo rdf:nodeID="A3"/>
    <creationInfo>
      <CreationInfo>
        <created>2010-02-03T00:00:00Z</created>
        <rdfs:comment>This is an example of an SPDX spreadsheet format</rdfs:comment>
        <creator>Person: Steven O'Neall</creator>
        <creator>Company: Source Code Company</creator>
        <creator>Tool: SourceCode-V1.2</creator>
      </CreationInfo>
    </creationInfo>
    <hasExtractedLicensingInfo rdf:nodeID="A2"/>
    <reviewed>
      <Review>
        <rdfs:comment>Another example reviewer.</rdfs:comment>
        <reviewDate>2011-03-13T00:00:00Z</reviewDate>
        <reviewer>Person: John Reviewer</reviewer>
      </Review>
    </reviewed>
  </SpdxDocument>
</rdf:RDF>