일부 HTML 태그를 나타내는 XML 문자열이 있습니다. 일부 XML을 선택하여 HTML로 가져 오려고합니다.XML을 HTML로 가져 오기
내가 현재 뭘하는지의 예 : 코드 페이지의 끝 부분에 링크를 추가해야하지만, 난 단지 연결하지의 텍스트를 볼 수 있습니다
<html>
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<div><p>som text</p></div>
<h1>hi there</h1>
<button>click</button>
<script>
xml = '<?xml version="1.0" encoding="utf-8"?><root><html><a href="#">the new link</a></html></root>';
$xml =$($.parseXML(xml));
$('button').on('click',function(){
var content = $xml.find('html:first').contents();
content.appendTo('body');
});
</script>
</body>
</html>
. HTML 태그는 작동하지 않습니다.
https://github.com/jindw/xmldom과 같은 jQuery 대신 다른 라이브러리를 사용했지만 그 결과는 같습니다. 업데이트 : 이것은 jsfiddle 링크입니다. http://jsfiddle.net/V4gHz/
.html() XML 문서로 작업하지 않습니다. 내부 innerHTML 함수를 사용하기 때문입니다. –
'.text()'는 어떨까요? – Jashwant
nope. 전혀 작동하지 않습니다 –