【问题标题】:jQuery XML object to stringjQuery XML 对象到字符串
【发布时间】:2012-07-30 00:29:21
【问题描述】:

我在 jQuery 中有一个 XML 对象:

var xml_srt = ^xml string^;    
xmlDoc = $.parseXML( xml_string );
xml = $( xmlDoc );

它工作正常,但我不知道如何从这个对象创建一个字符串。

如果我使用console.log(xml);,那就没问题了。但我需要一个字符串。

【问题讨论】:

  • 如果有帮助,你可以试试 $(xml) 把它变成一个 jQuery 对象
  • 你的意思是什么字符串?创建一个新的 xml 元素、读取一个元素或更改一个元素的值?问候
  • 我需要所有 xml 字符串例如:RSS Title

标签: jquery xml-parsing


【解决方案1】:

使用这个例子

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>

<p id="someElement"></p>
<p id="anotherElement"></p>



<script>
var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
    xmlDoc = $.parseXML( xml ),
    $xml = $( xmlDoc ),
    $title = $xml.find( "title" );

/* append "RSS Title" to #someElement */
$( "#someElement" ).append( $title.text() );

/* change the title to "XML Title" */
$title.text( "XML Title" );

/* append "XML Title" to #anotherElement */
$( "#anotherElement" ).append( $title.text() );
</script>

</body>
</html>

更多信息:http://api.jquery.com/jQuery.parseXML/

【讨论】:

  • 这是显示,但只是文本。我需要完整的 xml 字符串:like-> RSS Title
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-04
  • 2012-10-28
  • 2013-06-20
  • 2015-12-24
  • 2011-05-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多