我正在创建一个xml架构,我想确保所有元素中的值都是CDATA元素.
有没有办法使用XML模式强制执行此操作?
我想解析包含在CDATA中的任何HTML数据.
举个例子 <![CDATA[<table><tr><td>Approved</td></tr></table>]]>
谢谢!
我刚刚开始在PHP和Javascript环境中学习XML,我遇到了一个问题.
所以问题是我想将HTML标记放在XML中,然后能够通过PHP提取它并将HTML嵌入到使用SimpleXML读取XML的不同文件中.我正在用一些东西回应它
echo $child->asXML();
但是,当然CDATA标签仍在那里,它不起作用.所以,我的问题是,是否有一种方法可以以不同的方式嵌入HTML标记,XML解析器可以忽略它,但可以在HTML文档中使用,或B.从代码中剥离CDATA标记的方法?
我正在尝试使用我正在编写的DTD验证某些xml,但我总是在使用CDATA数据类型的元素上获得验证错误.像这样
<!ELEMENT title (#CDATA)>
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用textmate xml验证(XMLlint)和在线验证器(w3Schools)验证,我总是得到这个错误:
error: ContentDecl : Name or '(' expected
Run Code Online (Sandbox Code Playgroud)
谁能解释一下这里发生了什么?
干杯
完整的xml和dtd的例子(我从这里拿了这个,所以我希望它有效):
<?xml version="1.0"?>
<!DOCTYPE bookstore [
<!ELEMENT bookstore (name,topic+)>
<!ELEMENT topic (name,book*)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT book (title,author)>
<!ELEMENT title (#CDATA)>
<!ELEMENT author (#CDATA)>
<!ELEMENT isbn (#PCDATA)>
<!ATTLIST book isbn CDATA "0">
]>
<bookstore>
<name>Mike's Store</name>
<topic>
<name>XML</name>
<book isbn="123-456-789">
<title>Mike's Guide To DTD's and XML Schemas<</title>
<author>Mike Jervis</author>
</book>
</topic>
</bookstore>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用powershell读取rss feed,但我无法在feed中提取cdata-section
这是一个Feed的片段(为了节省空间而剪切了一些项目):
<item rdf:about="http://philadelphia.craigslist.org/ctd/blahblah.html">
<title>
<![CDATA[2006 BMW 650I,BLACK/BLACK/SPORT/AUTO ]]>
</title>
...
<dc:title>
<![CDATA[2006 BMW 650I,BLACK/BLACK/SPORT/AUTO ]]>
</dc:title>
<dc:type>text</dc:type>
<dcterms:issued>2011-11-28T22:15:55-05:00</dcterms:issued>
</item>
Run Code Online (Sandbox Code Playgroud)
和Powershell脚本:
$rssFeed = [xml](New-Object System.Net.WebClient).DownloadString('http://philadelphia.craigslist.org/sss/index.rss')
foreach ($item in $rssFeed.rdf.item) { $item.title }
Run Code Online (Sandbox Code Playgroud)
产生这个:
#cdata-section
--------------
2006 BMW 650I,BLACK/BLACK/SPORT/AUTO
2006 BMW 650I,BLACK/BLACK/SPORT/AUTO
Run Code Online (Sandbox Code Playgroud)
如何提取cdata-section?
我尝试了一些变体,例如$ item.title."#cdata-section"和$ item.title.InnerText,它们什么都不返回.我试过$ item.title | gm,我看到#cdata-section列为属性.我错过了什么?
谢谢.
<item><title>this is title</title><guid isPermaLink="true">http://www.i.com/video/nokia-lumia-920-deki-pureview_2879.html</guid><link>http://www.i.com/video/nokia-lumia-920-deki-pureview_2879.html</link>
<description><![CDATA[this is the info.]]></description>
<pubDate>Wed, 5 Sep 2012 22:10:00 UT</pubDate>
<media:content type="image/jpg" expression="sample" fileSize="2956" medium="image" url="http://media.chip.com.tr/images/content/video/88/201209060102428081-0.jpg"/>
<enclosure type="image/jpg" url="http://media.chip.com.tr/images/content/video/88/201209060102428081-0.jpg" length="2956"/></item>
Run Code Online (Sandbox Code Playgroud)
我想在<"description">中阅读CDATA
我写了这个
var x = e.Result;// e is downlaoded xml file
var videos = XElement.Parse(e.Result);
var fList = (from haber in videos.Descendants("channel").Elements("item")
select new Video
{
title = haber.Element("title").Value,
link = haber.Element("link").Value,
//description = ???????
}).ToList();
Run Code Online (Sandbox Code Playgroud)
我应该写什么描述?//编辑答案:同样的方式
但如果描述像这样?
<![CDATA[<p>Zombiler ad?na ne umduk ne bulduk!</p> <p> </p><p><img style="margin: 5px 0px 5px 5px; border: 1px solid #333333; float: …Run Code Online (Sandbox Code Playgroud) 我不需要marshaller,我已经有了XML文件.所以我按照本指南来了解如何解组CDATA中的内容.但是,我发现,如果我跳过主要的编组部分并且只做解组部分,它似乎不起作用.所以我的主要内容仅限于以下内容
Book book2 = JAXBXMLHandler.unmarshal(new File("book.xml"));
System.out.println(book2); //<-- return null.
Run Code Online (Sandbox Code Playgroud)
我期待看到CDATA中的任何内容.我确信我错过了一些东西,但不确定是什么.
我是SOAP新手,我想创建SOAP请求,如下所示
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<SOAP-ENV:Header/>
<soapenv:Body>
<tem:RequestData>
<tem:requestDocument>
<![CDATA[
<Request>
<Authentication CMId="68" Function="1" Guid="5594FB83-F4D4-431F-B3C5-EA6D7A8BA795" Password="poihg321TR"/>
<Establishment Id="4297867"/>
</Request>
]]>
</tem:requestDocument>
</tem:RequestData>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
我在教程中找到了创建SOAP请求的代码
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage sm = mf.createMessage();
SOAPEnvelope envelope = sm.getSOAPPart().getEnvelope();
envelope.addNamespaceDeclaration("soap", "http://schemas.xmlsoap.org/soap/envelope/");
envelope.setPrefix("soapenv");
envelope.setAttribute("xmlns:tem", "http://tempuri.org/");
SOAPBody body = envelope.getBody();
body.setPrefix("soapenv");
SOAPElement requestData = body.addChildElement("RequestData");
requestData.setPrefix("tem");
SOAPElement requestDoc = requestData.addChildElement("requestDocument","tem","http://tempuri.org/");
requestDoc.addTextNode(" <![CDATA[");
SOAPElement request = requestDoc.addChildElement("Request");
SOAPElement authentication = request.addChildElement("Authentication");
authentication.setAttribute("CMId", "68");
authentication.setAttribute("Guid", "5594FB83-F4D4-431F-B3C5-EA6D7A8BA795");
authentication.setAttribute("Password", "poihg321TR");
authentication.setAttribute("Function", "1");
SOAPElement establishment = request.addChildElement("Establishment");
establishment.setAttribute("Id", …Run Code Online (Sandbox Code Playgroud) 我在我的网页上插入了一些js代码(由第三方服务提供),这打破了我的html验证.我该如何解决这个问题?CDATA没有做到这一点.这是我的示例代码段:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test</title>
<script type="text/javascript">
/*<![CDATA[*/
document.write('<script src="//sharebutton.net/plugin/sharebutton.php?type=horizontal&u=' + encodeURIComponent(document.location.href) + '"></scr' + 'ipt>');
/*]]>*/
</script>
</head>
<body>
<p>test</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
而在这里,你可以找到验证的结果.
我试图读取此xml: xml rss文件
但是没有成功..有这个错误
Warning: simplexml_load_file(): http://noticias.perfil.com/feed/:232: parser error : CData section not finished <p>La sola lectura de los datos estadísticos desp in D:\xampp\FerreWoo\scrap-rvnot.php on line 43
Warning: simplexml_load_file(): Isis, con lo que habría logrado un nuevo respaldo a sus proyectos terroristas. in D:\xampp\FerreWoo\scrap-rvnot.php on line 43
Warning: simplexml_load_file(): ^ in D:\xampp\FerreWoo\scrap-rvnot.php on line 43
Run Code Online (Sandbox Code Playgroud)
我正在使用此代码:
$feed = simplexml_load_file($urls, null, LIBXML_NOCDATA);
Run Code Online (Sandbox Code Playgroud)
我也尝试使用cURL,但是仍然出现相同的错误。
我知道de xml文件可能不正确...但是必须有一种读取方法,对吗?
cdata ×10
xml ×4
c# ×2
java ×2
php ×2
rss ×2
dtd ×1
html ×1
javascript ×1
jaxb ×1
powershell ×1
regex ×1
simplexml ×1
soap ×1
validation ×1
web-services ×1
xml-parsing ×1
xsd ×1