dongyaobo9081 2011-05-10 09:41
浏览 103
已采纳

XML验证,嵌套的XSD和UNC路径

I want to validate an XML document against a local XSD file using XMLReader on PHP/5.3.0. The schema is called test.xsd and it contains a reference to a second schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:include schemaLocation="common.xsd"/>

I have a copy of all files in the same directory. The relevant part of the code looks like this:

<?php

define('DIR_XML', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR);

$oXMLReader = new XMLReader;

$oXMLReader->open('test.xml');
$oXMLReader->setSchema(DIR_XML . 'test.xsd');

while( $oXMLReader->read() ){
}
$oXMLReader->close();

?>

My code works fine if the samples directory is local to the web server and reachable by a drive letter, e.g.:

define('DIR_XML', 'C:\samples' . DIRECTORY_SEPARATOR);

However, real data is in a network drive reachable by UNC path:

\\SERVER\WEB PROJECTS\foo\samples

And here's the problem: in such case (and only in such case) PHP loads test.xsd just fine but it cannot find common.xsd. I get a warning:

Warning: XMLReader::setSchema() [xmlreader.setschema]: Unable to set schema. This must be set prior to reading or schema contains errors.

... and the following XML errors:

Warning 1549 (Start element): failed to load external entity "/SERVER/WEB%20PROJECTS/foo/samples/common.xsd"

Error 3050 (Start element): Element '{http://www.w3.org/2001/XMLSchema}include': Failed to load the document '/SERVER/WEB%20PROJECTS/foo/samples/common.xsd' for inclusion.

It seems that PHP is misinterpreting the UNC path as a URL :-?

Is there any option or trick to fix this?

  • 写回答

2条回答 默认 最新

  • dreamlife2014 2013-07-01 08:35
    关注

    i ran into a similar issue and the only way i could fix it was using a symlink from local HDD to UNC path (windows): mklink /D "C:\SomeDir" "//Some//UNC//Path"

    would have thought that this would also work on linux

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?