我有一个非常大的xml。它有字段Like
<SegrigatedQualification>
<EducationSplit>
<University><![CDATA[G. H. Raisoni College of Engineering]]></University>
<Degree><![CDATA[Engineering]]></Degree>
<Year><![CDATA[2011]]></Year>
</EducationSplit>
<EducationSplit>
<University><![CDATA[G. H. Raisoni College of Engineering]]></University>
<Degree><![CDATA[Engineering]]></Degree>
<Year><![CDATA[2010]]></Year>
</EducationSplit>
<EducationSplit>
<University><![CDATA[G. H. Raisoni College of Engineering]]></University>
<Degree><![CDATA[Engineering]]></Degree>
<Year><![CDATA[2009]]></Year>
</EducationSplit>
<EducationSplit>
<University><![CDATA[Diploma I.T]]></University>
<Degree><![CDATA[Diploma I.T]]></Degree>
<Year><![CDATA[2008]]></Year>
</EducationSplit>
<EducationSplit>
<University><![CDATA[Nasik Board]]></University>
<Degree><![CDATA[S.S.C]]></Degree>
<Year><![CDATA[2003]]></Year>
</EducationSplit>
</SegrigatedQualification>
我想映射字段和make表,然后将所有xml的信息存储到表中。问题是,如果我创建一个专栏SagrigratedQualificaton,我如何将教育分割或大学,学位,年份存储在一行?因为如果我创建单独的列,大学,学位等的信息将采取两行或更多行,这样表变得多余。将xml映射到表中的最佳方法是什么?
答案 0 :(得分:0)
关系数据库...每个xml结构应该是不同表中的不同记录。 或者只是保持简单并将其存储在某些TEXT或BLOB字段中。
答案 1 :(得分:0)
您可以使用MagicParser之类的东西来提取数据,然后轻松地将其映射到您自己的表格和字段。
答案 2 :(得分:0)
<?php
require("MagicParser.php");
function myRecordHandler($record){
// This is where you write your code to process each record, such as loading a database
// The following code will print out each field in your sample data:
print $record["EDUCATIONSPLIT"];
print $record["UNIVERSITY"];
print $record["DEGREE"];
print $record["YEAR"];
}
$data = ""; // string variable contianing the data to parse
MagicParser_parse("string://".$data,"myRecordHandler","xml|SEGRIGATEDQUALIFICATION/EDUCATIONSPLIT/");
?>
注意:如果你想从实际文件中加载它,那么你只需删除$ data引用并像这样制作MagicParser_parse:
MagicParser_parse("your-xml-file.xml".$data,"myRecordHandler","xml|SEGRIGATEDQUALIFICATION/EDUCATIONSPLIT/");