enyo框架的webos中的xml解析
请帮我解决以下问题。
问题出在xml解析上 我的xml代码是:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root type="object">
<codeListValue type="object">
<personnelCategory type="array">
<item type="string">Regular</item>
<item type="string">International</item>
<item type="string">Contractor</item>
<item type="string">System</item>
<item type="string">Employee</item>
</personnelCategory>
<pcImages type="array">
<item type="string">Windows</item>
<item type="string">Linux</item>
<item type="string">MAC OS</item>
<item type="string">Engineering Image</item>
</pcImages>
</codeListValue>
</root>
解析代码与web os sdk中的相同。解析部分在这里:
parseXML: function() {
this.items = [];
//this.path="/root";
this.url='Values.xml';
this.$.getGoogleResults.url = this.url;
this.$.getGoogleResults.call();
},
... ... gotResultsSuccess: function(inSender, inResponse) {
var xmlstring = inResponse;
var parser = new DOMParser();
var xmlobject = parser.parseFromString(xmlstring, "text/xml");
var nodes = document.evaluate('/root', xmlobject, null, XPathResult.ANY_TYPE, null);
var result = nodes.iterateNext();
//alert(result.textContent);
var i=0;
while(result)
{
this.items[i] = result.childNodes[0].nodeValue;
i++;
result=nodes.iterateNext();
}
this.items=result.textContent;
this.$.header.setContent(this.items);// [ this is a header component i have defined and i am setting its content here]
},
我得到的结果为 常规国际承包商系统...工程图像
XML 中的完整文本内容正在连续显示。我如何获取单个节点和子节点。我正在获取所有这些的空值。请帮助提供一些代码示例。
谢谢 :)
please help me with the following problem.
the problem is in xml parsing
my xml code is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root type="object">
<codeListValue type="object">
<personnelCategory type="array">
<item type="string">Regular</item>
<item type="string">International</item>
<item type="string">Contractor</item>
<item type="string">System</item>
<item type="string">Employee</item>
</personnelCategory>
<pcImages type="array">
<item type="string">Windows</item>
<item type="string">Linux</item>
<item type="string">MAC OS</item>
<item type="string">Engineering Image</item>
</pcImages>
</codeListValue>
</root>
the parsing code is the same as that in web os sdk.The parsing part is here:
parseXML: function() {
this.items = [];
//this.path="/root";
this.url='Values.xml';
this.$.getGoogleResults.url = this.url;
this.$.getGoogleResults.call();
},
...
...
gotResultsSuccess: function(inSender, inResponse) {
var xmlstring = inResponse;
var parser = new DOMParser();
var xmlobject = parser.parseFromString(xmlstring, "text/xml");
var nodes = document.evaluate('/root', xmlobject, null, XPathResult.ANY_TYPE, null);
var result = nodes.iterateNext();
//alert(result.textContent);
var i=0;
while(result)
{
this.items[i] = result.childNodes[0].nodeValue;
i++;
result=nodes.iterateNext();
}
this.items=result.textContent;
this.$.header.setContent(this.items);// [ this is a header component i have defined and i am setting its content here]
},
I am getting the result as
Regular International contractor System ... Engineering image
the complete text content in the XML is getting diaplayed serially.how do i get individual nodes and child nodes.i am getting null values for all these.PLease help with some code examples.
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码中的问题是循环仅工作一次,即只有一个子节点。
下面的代码将检索所有子节点。
希望这有帮助!
The problem in your code is that the loop works only once, ie, there is only one child node.
The code below will retrieve all child nodes.
Hope this helps!
我不太确定您想要做什么,但这是我使用 xml 的方式:
使用 WebService 组件并将 handleAs 设置为 xml。
在 onsuccess 函数上,只需获取结果参数并执行以下操作:
这将返回数组中名为“some_element”的所有元素。
您可以在 http://www.w3schools.com/xml/xml_dom 阅读有关 javascript xml 解析的更多信息。 ASP
I'm not quite sure what you want to do but here is how I work with xml:
Use a WebService component and set handleAs as xml.
On the onsuccess function , just grab the result parameter and do:
This will return all the elements called "some_element" in an array.
You can read more about javascript xml parsing at http://www.w3schools.com/xml/xml_dom.asp