如何将xml加载到webview android中

如何将xml加载到webview android中,android,webview,Android,Webview,我有一个xml文件,我想将xml内容加载到一个web视图中,在该视图中,web视图将膨胀到一个图库。我已经解析并能够获得解析的值,但是如何将xml内容加载到web视图中呢?我对此一无所知。请找人帮帮我。一个xml文件并不总是一个网页。您必须在loadUrl()like中提供一个有效的网页 wv.loadUrl("http://www.bbc.co.uk""); 或者,如果您有原始html,请使用: String summary = "<html><body>You

我有一个xml文件,我想将xml内容加载到一个web视图中,在该视图中,web视图将膨胀到一个图库。我已经解析并能够获得解析的值,但是如何将xml内容加载到web视图中呢?我对此一无所知。请找人帮帮我。

一个
xml
文件并不总是一个网页。您必须在
loadUrl()
like中提供一个有效的网页

  wv.loadUrl("http://www.bbc.co.uk"");
或者,如果您有原始html,请使用:

 String summary = "<html><body>You scored <b>192</b> points.</body></html>";
 webview.loadData(summary, "text/html", null);
String summary=“你得了192分。”;
loadData(摘要,“text/html”,空);

(是的,Android的UI使用xml文件。它使用xml作为框架来扩展视图)

我认为您需要在标签中显示内容

然后解析xml,并将webview显示为:

myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadDataWithBaseURL(null, myPreviewContents, mime, encoding, null);
其中
myPreviewContents
为:

<p>Early in my career I took responsibility for managing people. I managed up to 250 highly trained professionals who worked as a tight-knit team. It didn’t matter that I was the youngest person in the team! For over 20 years I’ve been working with individuals and organizations to help them improve their management of people. This has ranged from military personnel to entrepreneurs, from charities to government departments. I’ve learned many secrets and tricks over these years. Some I’ve discovered for myself, but many I’ve learned from others. Humans are wonderfully inventive!</p>
        <p>This book aims to help you improve your skills at managing people – to help you find ways in which everybody benefits. It contains 50 secrets, grouped into seven themed chapters.</p> 
    <p>
    <ul>
    <li>
    <span class='pointHeading'>Build on a strong foundation.</span><span class='normalText'>You must understand what type of leader or manager you want to be. Your employer may give guidelines, but you must exert control over your day-to-day behaviour.</span>   
    </li>
    <li>
    <span class='pointHeading'>Create a great team.</span><span class='normalText'>This shows how to choose the right people and quickly build a functioning team.</span>   
    </li>
    <li>
    <span class='pointHeading'>Set goals and targets.</span><span class='normalText'>By setting people effective targets and goals, you can monitor progress and offer appropriate rewards.</span>   
    </li>
    <li>
    <span class='pointHeading'>Motivate yourself and your people.</span><span class='normalText'>Implementing ways to motivate people is ultimately much easier than having to cajole and constantly monitor unmotivated people.</span>   
    </li>
    <li>
    <span class='pointHeading'>Manage good performance.</span><span class='normalText'>You need to recognize good performance – reward it, develop it, perpetuate it and spread it to others.  Otherwise you will lose your good performers and be left only with the poor ones.</span>   
    </li>
    <li>
    <span class='pointHeading'>Manage poor performance.</span><span class='normalText'>Some managers find ways of managing around poor performance without tackling the poor performance itself. However, this encourages more poor performance, from both the original perpetrator and everyone else. Know how to tackle the problems head on.</span>   
    </li>
    <li>
    <span class='pointHeading'>Develop your people.</span><span class='normalText'>Though often overlooked by managers, another fundamental task is developing people. You need to improve the less able, stretch and reward the able, plan succession for the future and mentor your people’s changing needs. </span>   
    </li>
    </ul>
    </p>
    <p>Managing people is a hugely complex area in which you never stop learning. The secrets contained in this book will help you make massive strides towards succeeding in this fascinating role.</p>
    ]]>
在我职业生涯的早期,我负责管理人员。我管理着多达250名训练有素的专业人士,他们组成了一个紧密的团队。我是队里最年轻的人并不重要!20多年来,我一直在与个人和组织合作,帮助他们改进人员管理。这包括从军事人员到企业家,从慈善机构到政府部门。这些年来我学到了很多秘密和技巧。有些是我自己发现的,但很多是我从别人那里学到的。人类是非常有创造力的

本书旨在帮助您提高管理人员的技能,帮助您找到让每个人都受益的方法。它包含50个秘密,分为七个主题章节。

  • 建立一个坚实的基础。你必须了解你想成为什么样的领导者或管理者。你的雇主可能会提供指导,但你必须控制你的日常行为。
  • 创建一个伟大的团队。这展示了如何选择合适的人并快速建立一个有效的团队。
  • 设定目标和指标。通过为员工设定有效的目标和指标,您可以监控进度并提供适当的奖励。
  • 激励你自己和你的员工。实施激励员工的方法最终要比哄骗和不断监控没有动力的员工容易得多。
  • 管理好绩效。你需要认可好的绩效——奖励、发展、延续并传播给他人。否则,你将失去优秀的员工,只剩下差劲的员工。
  • 管理糟糕的绩效。一些管理者找到了管理糟糕绩效的方法,却没有解决糟糕的绩效本身。然而,这鼓励了更糟糕的表现,无论是最初的肇事者还是其他人。知道如何迎头解决问题。
  • 培养你的员工。尽管管理者经常忽视,但另一项基本任务是培养员工。你需要改进能力较弱的人,拓展和奖励能力较强的人,为未来规划继任计划,指导员工不断变化的需求。

管理人员是一个非常复杂的领域,你永远不会停止学习。本书中包含的秘密将帮助你在这个迷人的角色上取得巨大的成功

]]>
您可以使用xsl转换xml,然后将生成的字符串加载到webivew(我相信是webview.loaddata)


参见转换xml示例。

请遵循android开发者关于xml解析的教程,下载示例代码并根据您的xml文件进行修改。它首先解析一个XML,然后继续创建一个HTML代码字符串,最后在一个简单的网络视图中呈现这个HTML字符串。

我怎么做我只有XML而没有HTML..我必须将XML转换成HTML吗?你必须向我展示XML包含的内容。请记住,xml本身不能用于呈现网页。只有当你的文件可以通过浏览器如Chrome或FireFox呈现时,WebView才能呈现它。雷诺我已经添加了我的xml,请查看并帮助我