|
| 1 | +--TEST-- |
| 2 | +DOMEntity fields |
| 3 | +--EXTENSIONS-- |
| 4 | +dom |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | +$xmlString = <<<XML |
| 8 | +<?xml version="1.0"?> |
| 9 | +<!DOCTYPE test [ |
| 10 | + <!ENTITY sampleInternalEntity "This is a sample entity value."> |
| 11 | + <!ENTITY sampleExternalSystemWithNotationName SYSTEM "external.stuff" NDATA stuff> |
| 12 | + <!ENTITY sampleExternalSystemWithoutNotationName SYSTEM "external.stuff" NDATA > |
| 13 | + <!ENTITY sampleExternalPublicWithNotationName1 PUBLIC "public id" "external.stuff" NDATA stuff> |
| 14 | + <!ENTITY sampleExternalPublicWithNotationName2 PUBLIC "" "external.stuff" NDATA stuff> |
| 15 | + <!ENTITY sampleExternalPublicWithoutNotationName1 PUBLIC "public id" "external.stuff" NDATA > |
| 16 | + <!ENTITY sampleExternalPublicWithoutNotationName2 PUBLIC "" "external.stuff" NDATA > |
| 17 | +]> |
| 18 | +<root/> |
| 19 | +XML; |
| 20 | + |
| 21 | +$dom = new DOMDocument(); |
| 22 | +$dom->loadXML($xmlString); |
| 23 | + |
| 24 | +// Sort them, the iteration order isn't defined |
| 25 | +$entities = iterator_to_array($dom->doctype->entities); |
| 26 | +ksort($entities); |
| 27 | + |
| 28 | +foreach ($entities as $entity) { |
| 29 | + echo "Entity name: {$entity->nodeName}\n"; |
| 30 | + echo "publicId: "; |
| 31 | + var_dump($entity->publicId); |
| 32 | + echo "systemId: "; |
| 33 | + var_dump($entity->systemId); |
| 34 | + echo "notationName: "; |
| 35 | + var_dump($entity->notationName); |
| 36 | + echo "actualEncoding: "; |
| 37 | + var_dump($entity->actualEncoding); |
| 38 | + echo "encoding: "; |
| 39 | + var_dump($entity->encoding); |
| 40 | + echo "version: "; |
| 41 | + var_dump($entity->version); |
| 42 | + echo "\n"; |
| 43 | +} |
| 44 | +?> |
| 45 | +--EXPECT-- |
| 46 | +Entity name: sampleExternalPublicWithNotationName1 |
| 47 | +publicId: string(9) "public id" |
| 48 | +systemId: string(14) "external.stuff" |
| 49 | +notationName: string(5) "stuff" |
| 50 | +actualEncoding: NULL |
| 51 | +encoding: NULL |
| 52 | +version: NULL |
| 53 | + |
| 54 | +Entity name: sampleExternalPublicWithNotationName2 |
| 55 | +publicId: string(0) "" |
| 56 | +systemId: string(14) "external.stuff" |
| 57 | +notationName: string(5) "stuff" |
| 58 | +actualEncoding: NULL |
| 59 | +encoding: NULL |
| 60 | +version: NULL |
| 61 | + |
| 62 | +Entity name: sampleExternalPublicWithoutNotationName1 |
| 63 | +publicId: string(9) "public id" |
| 64 | +systemId: string(14) "external.stuff" |
| 65 | +notationName: string(0) "" |
| 66 | +actualEncoding: NULL |
| 67 | +encoding: NULL |
| 68 | +version: NULL |
| 69 | + |
| 70 | +Entity name: sampleExternalPublicWithoutNotationName2 |
| 71 | +publicId: string(0) "" |
| 72 | +systemId: string(14) "external.stuff" |
| 73 | +notationName: string(0) "" |
| 74 | +actualEncoding: NULL |
| 75 | +encoding: NULL |
| 76 | +version: NULL |
| 77 | + |
| 78 | +Entity name: sampleExternalSystemWithNotationName |
| 79 | +publicId: NULL |
| 80 | +systemId: string(14) "external.stuff" |
| 81 | +notationName: string(5) "stuff" |
| 82 | +actualEncoding: NULL |
| 83 | +encoding: NULL |
| 84 | +version: NULL |
| 85 | + |
| 86 | +Entity name: sampleExternalSystemWithoutNotationName |
| 87 | +publicId: NULL |
| 88 | +systemId: string(14) "external.stuff" |
| 89 | +notationName: string(0) "" |
| 90 | +actualEncoding: NULL |
| 91 | +encoding: NULL |
| 92 | +version: NULL |
| 93 | + |
| 94 | +Entity name: sampleInternalEntity |
| 95 | +publicId: NULL |
| 96 | +systemId: NULL |
| 97 | +notationName: NULL |
| 98 | +actualEncoding: NULL |
| 99 | +encoding: NULL |
| 100 | +version: NULL |
0 commit comments