1

How can I get the xsi:nil attribute value using PHP's DOMDocument (and if necessary DOMXPath)?

<?xml version="1.0"?>
<Rows xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Row Index="1">
    <Email xsi:nil="true"/>
  </Row>
</Rows>

I tried getAttribute / getAttributeNS / getAttributeNodeNS, but without success.

Thanks in advance

3
  • $element->getAttribute('xsi:nil') ?? Commented Jun 21, 2013 at 14:34
  • As said, that doesn't work.. Commented Jun 21, 2013 at 14:40
  • 1
    3v4l.org/UmnAg Commented Jun 21, 2013 at 14:42

1 Answer 1

2

Try this code, i just tested and it works.

<?php
$xml=<<<EOF
<?xml version="1.0"?>
<Rows xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Row Index="1">
    <Email xsi:nil="true"/>
  </Row>
</Rows>
EOF;

$doc = new DOMDocument();
$doc->loadXML($xml);
$emails = $doc->getElementsByTagName('Email');
var_dump($emails->item(0)->attributes->getNamedItem('nil'));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.