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条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line