我正在研究nodejs-expressjs,我得到了原始XML的响应。我想将其转换为javascript数组或json数组,以便我可以检索域名及其状态。我想在HTML文件中显示该名称和状态。 Fowling是我的Raw XML
<?xml version='1.0' encoding="UTF-8" standalone="no" ?>
<!DOCTYPE OPS_envelope SYSTEM "ops.dtd">
<OPS_envelope>
<header>
<version>0.9</version>
</header>
<body>
<data_block>
<dt_assoc>
<item key="response_code">200</item>
<item key="response_text">Command completed successfully</item>
<item key="attributes">
<dt_assoc>
<item key="lookup">
<dt_assoc>
<item key="items">
<dt_array>
<item key="0">
<dt_assoc>
<item key="status">taken</item>
<item key="domain">ashok.com</item>
</dt_assoc>
</item>
<item key="1">
<dt_assoc>
<item key="domain">ashok.net</item>
<item key="status">available</item>
</dt_assoc>
</item>
<item key="2">
<dt_assoc>
<item key="domain">ashok.org</item>
<item key="status">available</item>
</dt_assoc>
</item>
<item key="3">
<dt_assoc>
<item key="domain">ashok.biz</item>
<item key="status">available</item>
</dt_assoc>
</item>
<item key="4">
<dt_assoc>
<item key="status">available</item>
<item key="domain">ashok.me</item>
</dt_assoc>
</item>
<item key="5">
<dt_assoc>
<item key="domain">ashok.website</item>
<item key="status">available</item>
<item key="has_claim">0</item>
</dt_assoc>
</item>
</dt_array>
</item>
<item key="response_text">Command completed successfully.</item>
<item key="response_code">200</item>
<item key="is_success">1</item>
<item key="count">6</item>
</dt_assoc>
</item>
<item key="personal_names">
<dt_assoc>
<item key="response_code"></item>
</dt_assoc>
</item>
</dt_assoc>
</item>
<item key="request_response_time">8.066</item>
<item key="protocol">XCP</item>
<item key="is_search_completed">1</item>
<item key="is_success">1</item>
<item key="action">REPLY</item>
</dt_assoc>
</data_block>
</body>
</OPS_envelope>
我已将其转换为
jsonXml = JSON.stringify(result.OPS_envelope.body.data_block.dt_assoc.item); console.dir(jsonXml);
'["Command completed successfully",{"dt_assoc":{"item":[{"dt_assoc":{"item":[{"dt_array":{"item":[{"dt_assoc":{"item":["anjali.com","taken"]}},{"dt_assoc":{"item":["available","anjali.net"]}},{"dt_assoc":{"item":["anjali.org","available"]}},{"dt_assoc":{"item":["available","anjali.biz"]}},{"dt_assoc":{"item":["available","anjali.me"]}},{"dt_assoc":{"item":["anjali.website","available","0"]}}]}},"Command completed successfully.","200","1","6"]}},{"dt_assoc":{"item":""}}]}},"200","REPLY","1","1","XCP","8.067"]'
当我使用
时var json = JSON.parse(jsonXml);
的console.log(JSON);
[ 'Command completed successfully',
{ dt_assoc: { item: [Object] } },
'200',
'REPLY',
'1',
'1',
'XCP',
'8.067' ]
我想检索域名,并将它们作为javascript数组从json输出中获取/可用,但我无法做到。
或者您可能知道检索domain_name和status的任何其他方法。
请帮助我。