2014-12-19 59 views
0

抱歉,因为提出这样一个模糊的问题,我急着去工作,我的错,道歉。XML to coldfusion和mysql

这是完整的问题。

我有一个XML文件,该文件的大小7MB,我想提取信息,并把它添加到MySQL和创建与提取信息的新表。

下面是XML文件的结构(原始文件具有超过1185的属性),本实施例中只有一个。

我想知道我怎么能删除不从ColdFusion的饲料所需的元素,然后导入所需的字段到表中的MySQL

<?xml version="1.0" encoding="UTF-8"?> 
<root> 
<properties> 
<property> 
<details> 
    <propertyid>112</propertyid> 
    <name>Spain, Costa del Sol, Marbella, Capanes del Golf Apartment- 5* hotel facilities</name> 
    <reference>2360</reference> 
    <price>376242</price> 
    <pricetype id="4">N/A</pricetype> 
    <status id="3">For Sale</status> 
    <description> 
     <p>Capanes del Golf is one of the most exclusive project in Costa del Sol at this time. The complex with luxurious apartments is located near the road to Benahavis and just a few minutes away from the coast.</p> 
     <p>Positioned at the very heart of the New Marbella Club Golf Course (El Higueral Golf), its location is unique as it is totally surrounded by the course. As well as its stunning location at the heart of the course, the complex also enjoys more than 50.000 m2 of carefully landscaped Mediterranean gardens with water areas, swimmingpools as well as a private Club Social with Spa and fitness.</p> 
     <p>All of the apartments at Capanes del Golf have a golf share to the New Marbella Club Golf Course included in the sales price, this allows the client full access to the golf course surrounding the project. Capanes del Golf is a project not just to be lived but also enjoyed as a home.</p> 
     <p> 
      <strong>Additional Features</strong> 
     </p> 
     <p>5 * Hotel facilties<br />Gym<br />Health spa available on site<br />Established on a Golf resort</p> 
    </description> 
    <levels>0</levels> 
    <bedrooms>2</bedrooms> 
    <bathrooms>1</bathrooms> 
    <areacovered>189</areacovered> 
    <areaplot>0</areaplot> 
    <areaveranda>0</areaveranda> 
    <areagarden>0</areagarden> 
    <promote>0</promote> 
    <sleeps>0</sleeps> 
    <deliverydate /> 
    <googlemapurl /> 
    <latitude /> 
    <longitude /> 
    <mapzoom /> 
    <mapactive>0</mapactive> 
    <investment /> 
    <ownernotes /> 
    <dateadded /> 
    <dateupdated>01/01/2013</dateupdated> 
    <sortweight>0</sortweight> 
    <urlalias>spain-costa-del-sol-marbella-hotel-facilities-1</urlalias> 
    <url>http://127.0.0.1/properties-for-sale/spain-costa-del-sol-marbella-hotel-facilities-1</url> 
</details> 
<location> 
    <country id="27" urlalias="spain">Spain</country> 
    <district id="52" urlalias="costa-del-sol">Costa del Sol</district> 
    <location id="929" urlalias="marbella">Marbella</location> 
</location> 
<types> 
    <type id="8" urlalias="apartment-flat">Apartment-Flat</type> 
</types> 
<categories /> 
<features /> 
<images> 
    <imageurl>http://127.0.0.1/media/property-images/spain-costa-del-sol-marbella-hotel-facilities_full_11.jpg</imageurl> 
    <imageurl>http://127.0.0.1/media/property-images/spain-costa-del-sol-marbella-hotel-facilities_full_12.jpg</imageurl> 
    <imageurl>http://127.0.0.1/media/property-images/spain-costa-del-sol-marbella-hotel-facilities_full_13.jpg</imageurl> 
    <imageurl>http://127.0.0.1/media/property-images/spain-costa-del-sol-marbella-hotel-facilities_full_14.jpg</imageurl> 
    <imageurl>http://127.0.0.1/media/property-images/spain-costa-del-sol-marbella-hotel-facilities_full_15.jpg</imageurl> 
    <imageurl>http://127.0.0.1/media/property-images/spain-costa-del-sol-marbella-hotel-facilities_full_16.jpg</imageurl> 
</images> 
</property> 
</properties> 
</root> 

林也是数据试图输出成JSON格式使用使用的代码通过以下雷蒙德卡姆登的ColdFusion IM:

<cfset cachedJSON = cacheGet("jsonstr")> 
<cfif isNull(cachedJSON)> 

<cfset xmlFile = expandPath("./xml/poj.xml")> 
<cfset xmlData = xmlParse(xmlFile)> 

<cfscript> 
function xmlToStruct(xml x) { 
var s = {}; 

if(xmlGetNodeType(x) == "DOCUMENT_NODE") { 
s[structKeyList(x)] = xmlToStruct(x[structKeyList(x)]); 
} 

if(structKeyExists(x, "xmlAttributes") && !structIsEmpty(x.xmlAttributes)) { 
s.attributes = {}; 
for(var item in x.xmlAttributes) { 
s.attributes[item] = x.xmlAttributes[item]; 
} 
} 

if(structKeyExists(x, "xmlChildren")) { 
for(var i=1; i<=arrayLen(x.xmlChildren); i++) { 
if(structKeyExists(s, x.xmlchildren[i].xmlname)) { 
if(!isArray(s[x.xmlChildren[i].xmlname])) { 
var temp = s[x.xmlchildren[i].xmlname]; 
s[x.xmlchildren[i].xmlname] = [temp]; 
} 
arrayAppend(s[x.xmlchildren[i].xmlname], xmlToStruct(x.xmlChildren[i])); 
} else { 
s[x.xmlChildren[i].xmlName] = xmlToStruct(x.xmlChildren[i]); 
} 
} 
} 

return s; 
} 

cachedJSON = serializeJSON(xmlToStruct(xmlData)); 

</cfscript> 

<cfset cachePut("jsonstr", cachedJSON)> 

</cfif> 

<cfcontent reset="true" type="application/json"><cfoutput>#cachedJSON#</cfoutput> 

基本上这将是一个房地产网站这是越来越由WordPress的系统生成的XML提要。使用jquery函数解析xml并使用coldfusion serializeJSON函数输出的数据正常。我被xml结构中的节点弄糊涂了,因为我真正想要做的就是将它全部添加到mysql中的表中,并每天运行一次更新以更新数据库中的属性。我的Coldfusion和Java知识并不是最好的,所以请原谅我,如果我在这里困难。我想在数据库中存储所有内容的原因是,我可以拥有国家/地区/城市/城镇表,货币表,属性类型表等,以便我可以从这些字段构建搜索功能。

我试着将XML导入使用Navicat的导入功能的MySQL,但就是不工作我需要它作为很多的信息是在标签的方式。我希望我在这里有意义,我的意思是甚至需要将所有这些信息存储到数据库中,并直接从提要中显示属性?

+1

你能告诉我们你到目前为止所尝试过的吗?所以我们可以帮助您解决具体问题。 – 2014-12-19 08:31:32

+0

如果这个人在我的“答案”中对这个建议采取行动,那么我就会拒绝投票结束这个问题,从而使这个问题可行。 – 2014-12-19 08:39:44

+0

对不起,我会在几分钟内添加所有内容,对不起,我很抱歉,因为我很匆忙,我没有时间发布完整的问题。 – johnnyc0506 2014-12-19 08:41:29

回答

0

你没有注明你的任何努力找出如何用CFML来做到这一点,所以我会对你的建议做一个肤浅的回答,就像你建议你自己的研究一样。

ColdFusion对XML审问和操纵有一系列的支持。从这里开始:“Using XML and WDDX”。忽略关于WDDX的东西,但要阅读,试验并理解所有XML可能性。请特别注意以下功能:xmlSearch(),xmlTransform()。另外标题为“Modifying a ColdFusion XML object”的部分。

对于你问什么,建议阅读的文档,并就这些行动可能是帮助一个适当的水平。

如果你这样做,然后尝试一些,仍然有问题:张贴代码 - 或削减下来的摄制情况下只是演示问题(阅读:“Short, Self Contained, Correct (Compilable), Example”,以及文档我链接在其中) - 然后问一个更直接的问题。

我不知道如何更好地回答你的问题,你不指示沿着这个过程中,你有多远,所以不知道我会浪费我的时间你或许已经有一些提供建议尝试/理解/等等。我不想浪费我们的时间(尽管我更关心我自己的时间浪费,我承认这一点)。