2012-02-27 6 views
0

XML 피드를 사람이 읽을 수있는 형식으로 변환하려고 시도했지만 성공하지 못했습니다. 나는 tutorails 섹션에서 주어진 예제를 보려고 노력했지만 너무 복잡합니다. 누군가가 끝내야 할 일을 도와 주실 수 있습니까? 나는 xml을 파싱 할 때까지 잘 할 수있다.Google 스크립트를 사용하여 XML 데이터 구문 분석

Google 스크립트를 사용 중이며 출력이 Google 워드 프로세서에 있어야합니다. 여기

내가 여기에 내가 태그를 제거하고 단지 문서에 그것을 밖으로 인쇄하는 방법은 XML

<record> 
<details> 
<id>212929</id> 
<distance>0</distance> 
<category cat="8" sub="202" id="1201">General</category> 
<name>Text Book Center</name> 
<short_desc>One of Kenya's finest</short_desc> 
<long_desc> 
One of Kenya's leading bookshops, the Text Book Center offers a wide selection of titles. There is everything here from textbooks to fiction to the latest Information Technology titles. The range of maps is especially impressive. The shop is spacious and cool, giving shoppers plenty of room to browse the shelves upon shelves of books. Look out for the regular special offers. 
</long_desc> 
<address> 
<address1>Kijabe Street</address1> 
<city>Nairobi</city> 
<country>Kenya</country> 
<latitude>0</latitude> 
<longitude>0</longitude> 
</address> 
<neighborhood>Downtown</neighborhood> 
<phone>+254 2 330 340</phone> 
<email>[email protected]</email> 
<open_hours>8am-1pm; 2pm-5.30pm Mon-Sat.</open_hours> 
</details> 
</record> 
</records> 

에게 있습니다

var response = UrlFetchApp.fetch("http://getRecords.php?oauth_token=3e73c7&lat="+lat+"&lon="+lon+"&searchFor="+text+"&miles=100&response_type=xml"); 

    var doc = Xml.parse(response.getContentText(), true) 
var root = doc.getElement(); 
var entryList = "<ul>\n"; 

var entries = root.getElements("details"); 

    for (var i=0; i<entries.length; i++) { 
    var e = entries[i]; 
    var name = e.getElement("name").getText(); 

    } 



    entryList += "<li>name </li>" + name; 


    entryList += "</ul>\n"; 
    return entryList; 

지금까지 해낸 것입니다. 도와주세요

감사합니다

+0

같이하십시오. 다른 것으로 다시 포맷 하시겠습니까? –

+0

안녕하세요 이것은 Google 스크립트를 사용하고 있으며 출력은 Google 워드 프로세서에 있어야합니다. xml 태그없이 인쇄해야합니다. 어떤 사람이 내게이 점을 지적 할 수 있습니까 –

답변

1

루트 노드 열기 태그가 없습니다. 원래 의사 야? 아니면 그냥 붙여 넣기 오류?

내가 XML은 이미 사람이 읽을 수 있도록 설계되었다 생각이

var response = UrlFetchApp.fetch("http://getRecords.php? oauth_token=3e73c7&lat="+lat+"&lon="+lon+"&searchFor="+text+"&miles=100&response_type=xml"); 
var doc = Xml.parse(response.getContentText(), true); 
var records = doc.records.getElements("record"); 
var entryList = "<ul>\n"; 

for (var i=0; i < records.length; i++) { 
    var details = records[i].details; 
    var name = details.name.getText(); 
    entryList += "<li>" + name + "</li>\n"; 
} 

entryList += "</ul>\n"; 
return entryList; 
+0

고맙습니다 arunes. 그것의 붙여 넣기 오류 –

+0

내 솔루션 귀하의 질문에 대한 답변은 무엇입니까? 그러면 당신은 대답으로 받아 들일 수 있습니다. – arunes

+0

아니 arunes 내가 getEleements ("기록")에 eror를 받고있어 그것을 보여주는 TypeError : 개체 XmlDocument에서 getElements 함수를 찾을 수 없습니다. (라인 14) –

관련 문제