将本地 XML 文件值加载到 Javascript 变量中
尝试从本地 (c:\folder\xmlfile.xml) XML 配置文件读取各种值,并将它们放入也在同一本地计算机上运行的 HTA 内的 JavaScript 变量中。
本地 XML 文件包含:
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<Module name="LocalDB">
<Property name="Server" value="localhost\application" />
<Property name="Database" value="applicationdb" />
<Property name="UID" value="standarduser" />
<Property name="Password" value="defaultpw" />
</Module>
</configure>
打开并读取 XML 文件后,我需要将“applicationdb”、“standarduser”、“defaultpw”等各种值放入 JavaScript 变量中。
我一整天都在尝试,也许我的谷歌搜索没有我想象的那么强大,但似乎找不到任何真正的方向。
我已经了解到:
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
while(xmlDOC.readyState !=4) {};
xmlDOC=loadXMLDoc("xmlfile.xml");
我什至不完全确定这是正确的,但我无法找到有关如何在加载文件后解析这些值的说明。
感谢您花时间阅读并提供帮助。
Trying read various values from a local (c:\folder\xmlfile.xml) XML config file and put them into JavaScript variables within an HTA that is also running on the same local machine.
The local XML file contains:
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<Module name="LocalDB">
<Property name="Server" value="localhost\application" />
<Property name="Database" value="applicationdb" />
<Property name="UID" value="standarduser" />
<Property name="Password" value="defaultpw" />
</Module>
</configure>
I need to put the various values such as "applicationdb", "standarduser", "defaultpw", into JavaScript variables after opening and reading the XML file.
I've been trying all day, and maybe my google-fu isn't as strong as I thought but can't seem to find any real direction.
I've gotten as far as:
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
while(xmlDOC.readyState !=4) {};
xmlDOC=loadXMLDoc("xmlfile.xml");
I'm not entirely sure even that is correct, but I haven't been able to find instruction on how to parse the values once the file is loaded.
Thanks for taking the time to read and for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 xmlfile.xml 不是有效的 xml 文件。结束配置标记拼写错误,将无法加载。一旦解决了这个问题,您应该考虑使用 XPATH 查询来搜索 XML。
Your xmlfile.xml is not a valid xml file. The closing Configuration tag is incorrectly spelt and will failed to load. Once you fix that, you should consider using XPATH queries to search your XML.