Home >Web Front-end >HTML Tutorial >How to call the content of xml file in html? _html/css_WEB-ITnose

How to call the content of xml file in html? _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:55:211932browse

RT. You need to write a simple web page, but you need multi-language versions. Therefore, I want to create multiple XML files as text libraries in different languages ​​to facilitate later maintenance. But I have just come into contact with HTML and I don’t know how to call the content of the XML file in HTML?

For example:
Contents such as "menu" and "tools" should be displayed on the web page. Therefore, create a file named CN.xml and write "Menu" and "Tools" in it. Create another file named EN.xml and write "Menu" and "Tools" in it. In the Chinese version of HTML, where the "menu" needs to be displayed, the "menu" text is called from CN.xml and displayed. In the English version of HTML, where the "menu" needs to be displayed, the "Menu" text is called from EN.html and displayed.


Reply to discussion (solution)

http://expert.csdn.net/Expert/topic/2040/2040475.xml?temp=. 6216089

http://www.cnblogs.com/winsor-w/archive/2007/03/05/664552.html The above is wrong..

http://www. cnblogs.com/huacw/archive/2011/03/24/1994074.html
http://techpool.iteye.com/blog/649024

2L personal test valid (IE environment)

I have seen what 2L and 3L provided, but it is not the same as what I want. I don’t need to use the span function. Examples on the Internet basically use xml to store multiple object information of a certain class, but my xml contains either such data or a simple text library, such as the following:

bee03da89c3244274fe5edee4f2dfb6e
41a992d172d4058fa1f494159e00332c
;/data>
18496893d53adc60e5bd8999a49adef2

I want to call the text "menu" in html. How should I call it?

<script src="/Scripts/jquery-1.8.0.min.js" type="text/javascript"></script><script>var xml='<?xml version="1.0" encoding="GB2312" ?><Resource><data name="1">menu</data><data name="2">tool</data></Resource>';$(xml).find("data").each(function(i)            {console.log(this)alert($(this).text())            });</script>

<script src=scripts/jquery-1.8.3.min.js></script><script src=scripts/jquery.xpath.min.js></script><script>$(function() {  $('#x2').html($('xml').xpath('//.[@name=2]').text());  $('#x1').html($('xml').xpath('//.[@name=1]').text());});</script><xml><?xml version="1.0" encoding="GB2312" ?><Resource>        <data name="1">menu</data>        <data name="2">tool</data></Resource></xml><div id=x2></div><div id=x1></div>

<script src=scripts/jquery-1.8.3.min.js></script><script src=scripts/jquery.xpath.min.js></script><script>$(function() {  $('#x2').html($('xml').xpath('//.[@name=2]').text());  $('#x1').html($('xml').xpath('//.[@name=1]').text());});</script><xml><?xml version="1.0" encoding="GB2312" ?><Resource>        <data name="1">menu</data>        <data name="2">tool</data></Resource></xml><div id=x2></div><div id=x1></div>


Where should the entire code be placed? html file? For example, there is a link in my html, 323866e7e404477cb2316196bc4c2fa6menu5db79b134e9f6b82c0b36e0489ee08ed. Now I want to replace the plain text part of this statement with the text corresponding to name="1" in the xml file. It should be How to change this statement?

<script src="/Scripts/jquery-1.8.0.min.js" type="text/javascript"></script><script>var xml='<?xml version="1.0" encoding="GB2312" ?><Resource><data name="1">menu</data><data name="2">tool</data></Resource>';$(xml).find("data").each(function(i)            {console.log(this)alert($(this).text())            });</script>


Sorry, I’m not very familiar with html, so I don’t know much about it. Do these need to be placed in the head of html? What should I do when I specifically want to call the text of the entry with name=1 in xml? For example, there is a link in my html, 323866e7e404477cb2316196bc4c2fa6menu5db79b134e9f6b82c0b36e0489ee08ed. Now I want to replace the plain text part of this statement with the text corresponding to name="1" in the xml file. It should be How to change this statement?
Putting xml in html is just for testing convenience. In actual use, you can use $.ajax to load


$('a[href=munu]').html($('xml ').xpath('//.[@name=1]').text());


<script src="/Scripts/jquery-1.8.0.min.js" type="text/javascript"></script><script>var xml='<?xml version="1.0" encoding="GB2312" ?><Resource><data name="1">menu</data><data name="2">tool</data></Resource>';$(xml).find("data").each(function(i)            {console.log(this)alert($(this).text())            });</script>


Sorry, I'm not very familiar with HTML yet, so I don't know much about it. Should these be placed in the head of HTML? What should I do when I specifically want to call the text of the entry with name=1 in xml? For example, there is a link in my html, 323866e7e404477cb2316196bc4c2fa6menu5db79b134e9f6b82c0b36e0489ee08ed. Now I want to replace the plain text part of this statement with the text corresponding to name="1" in the xml file. It should be How to change this statement?


<script src="/Common/Scripts/jquery-1.8.0.min.js" type="text/javascript"></script><script>var xml='<?xml version="1.0" encoding="GB2312" ?><Resource><data name="1">menu</data><data name="2">tool</data></Resource>';alert($(xml).find("data[name=1]").text());</script>
You don’t need to put it in the head if you put it in html
Generally, xml is obtained using ajax


<script src="/Scripts/jquery-1.8.0.min.js" type="text/javascript"></script><script>var xml='<?xml version="1.0" encoding="GB2312" ?><Resource><data name="1">menu</data><data name="2">tool</data></Resource>';$(xml).find("data").each(function(i)            {console.log(this)alert($(this).text())            });</script>


Sorry, I’m not very new to HTML and don’t quite understand it. Do these need to be placed in the head of HTML? What should I do when I specifically want to call the text of the entry with name=1 in xml? For example, there is a link in my html, 323866e7e404477cb2316196bc4c2fa6menu5db79b134e9f6b82c0b36e0489ee08ed. Now I want to replace the plain text part of this statement with the text corresponding to name="1" in the xml file. It should be How to change this statement?



<script src="/Common/Scripts/jquery-1.8.0.min.js" type="text/javascript"></script><script>var xml='<?xml version="1.0" encoding="GB2312" ?><Resource><data name="1">menu</data><data name="2">tool</data></Resource>';$('a[href=munu]').html($(xml).find("data[name=1]").text());</script>
There are many great people

Thanks to the two masters slwsss and xuzuning, but I didn’t understand how to use this thing in the end. ...Later I found that it is easier to solve it with php, which is suitable for a complete novice like me

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn