0
나는 this 예제를 찾고 있었지만 제대로 작동하지 못했습니다.jQuery로 로컬 XML 파일을 생성하는 방법
사용자가 버튼을 클릭 할 때 로컬 XML 파일을 생성해야합니다.
나는 내가 좋아하는 뭔가를 시도이 하나
<array>
<dict>
<key>files</key>
<array>
<dict>
<key>date</key>
<string>2012/09/09</string>
<key>name</key>
<string>acatBriefing.pdf</string>
<key>description</key>
<string>ACAT Briefing</string>
</dict>
</array>
<key>subject</key>
<string>FAE approved ACAT Designations</string>
<key>presenter</key>
<string>Rebecca T. King</string>
<key>time</key>
<string>2:00 - 2:05 PM</string>
</dict>
</array>
같은 XML을 작성해야합니다 : 나는 jQuery로 로컬 XML 파일을 만드는 방법을
function generateXML(){
// Simple helper function creates a new element from a name, so you don't have to add the brackets etc.
$.createElement = function(name)
{
return $('<'+name+' />');
};
// JQ plugin appends a new element created from 'name' to each matched element.
$.fn.appendNewElement = function(name)
{
this.each(function(i)
{
$(this).append('<'+name+' />');
});
return this;
}
/* xml root element - because html() does not include the root element and we want to
* include <report /> in the output. There may be a better way to do this.
*/
var $root = $('<XMLDocument />');
$root.append
(
// one method of adding a basic structure
$('<plist />').append
(
$('<dict />').append
(
$('<key />').text('subject')
$('<string />').text('September 21')
$('<key />').text('date')
$('<string />').text('FOB10 Room')
$('<key />').text('time')
$('<string />').text('2.00 pm - 5.00 pm')
$('<key />').text('briefings')
$('<array />').append
(
$('<dict />').append
(
$('<key />').text('files')
$('<array />').append
(
$('<dict />').append
(
$('<key />').text('date')
$('<string />').text('09/09/2012')
$('<key />').text('name')
$('<string />').text('acatBriefing.pdf')
$('<key />').text('description')
$('<string />').text('ACAT Briefing')
)
)
$('<key />').text('subject')
$('<string />').text('FAE approved ACAT Designations')
$('<key />').text('presenter')
$('<string />').text('Rebecca T. King')
$('<key />').text('time')
$('<string />').text('2.00 - 2.05 PM')
)
)
)
)
);
alert($root.html());
}
나는 그것을 할 수 없습니다?
"로컬"으로부터 경고를 얻을 내
generateXML()
경우이 말에주의 당신은 메모리 내 뜻, 또는 실제로 저장 로컬 파일? –필요한 것은 올바른 xml 태그가 포함 된 문자열 또는 텍스트 파일입니다. –
문자열을 원한다면 실제로 문서를 만들고 건너 뛰고 문자열을 만듭니다. –