Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stringify and document element shortcuts to XML Document #67

Merged
merged 1 commit into from
Jan 14, 2024

Conversation

veewee
Copy link
Owner

@veewee veewee commented Jan 14, 2024

Q A
Type improvement
BC Break no
Fixed issues

Summary

Some functions I happen a lot are causing some verbosity. By adding them to the Document class, it makes it faster to do trivial stuff like e.g. Grabbing the document element or stringifying a part of the document.

document_element locator:

use VeeWee\Xml\Dom\Document;
use function VeeWee\Xml\Dom\Locator\document_element;

$doc = Document::fromXmlFile('some.xml');
$rootElement = $doc->locate(document_element());

// Since this is a common action, there is also a shortcut:
$doc->locateDocumentElement();

Stringify

use VeeWee\Xml\Dom\Document;

$doc = Document::fromXmlFile('some.xml');

// Get full XML including the XML declaration tag:
$xml = $doc->toXmlString();

// OR, get only the XML part without declaration:
$xml = $doc->stringifyDocumentElement();

// Or stringify a specific DOM node:
$xml = $doc->stringifyNode($someNode);

@veewee veewee added the enhancement New feature or request label Jan 14, 2024
@veewee veewee merged commit 143c565 into main Jan 14, 2024
30 checks passed
@veewee veewee deleted the shortcut-functions branch January 14, 2024 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant