我可以获取要在html中使用的xml标记值,还是可以使用<;ul>&&书信电报;il>;用javascript?
基本上,我有一个作业来获取xml数据并在html页面中显示它,所以xml数据如下所示我可以获取要在html中使用的xml标记值,还是可以使用<;ul>&&书信电报;il>;用javascript?,javascript,html,xml,Javascript,Html,Xml,基本上,我有一个作业来获取xml数据并在html页面中显示它,所以xml数据如下所示 <job> <id>4821a</id> <title>Engineer On Site</title> <url>https://www.google.com/</url> <company_name>Fast Connection, Ltd.</company_name> <compa
<job>
<id>4821a</id>
<title>Engineer On Site</title>
<url>https://www.google.com/</url>
<company_name>Fast Connection, Ltd.</company_name>
<company_logo>https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg</company_logo>
<country>United States</country>
<jobCategory>Engineering</jobCategory>
<jobIndustry>Information Technology and Services</jobIndustry>
<employmentType>Contract</employmentType>
</job>
<section class="site-section">
<div class="container">
<ul class="job mb-5">
<li class="job d-block d-sm-flex pb-3 pb-sm-0 align-items-center">
<a href="jobexample.html"></a>
<div class="job-logo">
<img src="images/job_logo_2.jpg" alt="Free Website Template by Free-Template.co" class="img-fluid">
</div>
<div class="job-about d-sm-flex custom-width w-100 justify-content-between mx-4">
<div class="job-position custom-width w-50 mb-3 mb-sm-0">
<h2>Insert-Job</h2>
<strong>Insert-Company</strong>
</div>
<div class="job-location mb-3 mb-sm-0 custom-width w-25">
<span class="icon-room"></span> Insert-City
</div>
<div class="job-meta">
<span class="badge badge-success">Insert-emplyementtype</span>
</div>
</div>
</li>
</ul>
</section>
4821a
现场工程师
https://www.google.com/
快速连接有限公司。
https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg
美国
工程类
信息技术和服务
合同
一段html代码如下所示
<job>
<id>4821a</id>
<title>Engineer On Site</title>
<url>https://www.google.com/</url>
<company_name>Fast Connection, Ltd.</company_name>
<company_logo>https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg</company_logo>
<country>United States</country>
<jobCategory>Engineering</jobCategory>
<jobIndustry>Information Technology and Services</jobIndustry>
<employmentType>Contract</employmentType>
</job>
<section class="site-section">
<div class="container">
<ul class="job mb-5">
<li class="job d-block d-sm-flex pb-3 pb-sm-0 align-items-center">
<a href="jobexample.html"></a>
<div class="job-logo">
<img src="images/job_logo_2.jpg" alt="Free Website Template by Free-Template.co" class="img-fluid">
</div>
<div class="job-about d-sm-flex custom-width w-100 justify-content-between mx-4">
<div class="job-position custom-width w-50 mb-3 mb-sm-0">
<h2>Insert-Job</h2>
<strong>Insert-Company</strong>
</div>
<div class="job-location mb-3 mb-sm-0 custom-width w-25">
<span class="icon-room"></span> Insert-City
</div>
<div class="job-meta">
<span class="badge badge-success">Insert-emplyementtype</span>
</div>
</div>
</li>
</ul>
</section>
-
插入作业
插入公司
插入城市
插入EmploymentType
所以基本上我必须获取xml数据并将其显示到html页面
根据我的搜索,通常html页面的UI组件被插入到脚本中,但是我们被告知要制作“使用section、ul和li等标记的更好的UI”而不是barebone表,如果有人在脚本中插入了标记,我找不到教程
因此,我的想法是将xml数据作为变量值,然后通过法线显示变量值
可以这样做吗,或者我应该在脚本本身中插入标记吗
编辑:例如,如果我的xml文件有多个数据,我是否可以使用“for”重复获取和显示xml数据?您可以使用它来读取xml信息。从这一点上,创建和添加元素就很容易了。开始的示例:
let text='';
文本+=”;
text+=“4821a”;
文本+=‘现场工程师’;
文本+='https://www.google.com/';
text+=“快速连接有限公司”;
文本+='https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg';
文本+=‘美国’;
文本+=‘工程’;
text+=‘信息技术与服务’;
文本+=‘合同’;
文本+=”;
让parser=newdomparser();
设xmlDoc=parser.parseFromString(text,“text/xml”);
让countries=xmlDoc.getElementsByTagName('country');
console.log(国家[0].childNodes[0].nodeValue);//美国
设ulist=document.createElement('ul');
让listitem=document.createElement('li');
listitem.innerText=国家[0]。子节点[0]。节点值;
ulist.appendChild(列表项)
文件.body.appendChild(ulist)代码>
所以我必须在DOMParser脚本中添加xml代码?我可以使用单独的xml文件吗?不,这只是一个例子。你可以从任何地方获得文本。