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

mixed text/element in node discards text #107

Closed
admonkey opened this issue Sep 12, 2016 · 2 comments
Closed

mixed text/element in node discards text #107

admonkey opened this issue Sep 12, 2016 · 2 comments
Labels

Comments

@admonkey
Copy link

If my document has mixed text/elements in a node, for example:

<root>
   <node>
      some text
      <sub>
          deep text
      </sub>
   </node>
</root>

then how can I parse some text?

It seems to be simply ignored/discarded when parsed.

Thanks!

@evert evert added the question label Sep 13, 2016
@evert
Copy link
Member

evert commented Sep 13, 2016

Hi @admonkey,

This is by design. The goal of the default deserializer is to easily parse the most common-case. Adding support for mixing text and elements would make parsing unnecessarily complicated.

However, there are specific areas where this makes sense. One example is XHTML embedded into Atom files.

So the question here is, what do you want to do with the data? If your actual use-cases is indeed XHTML inside Atom, you likely want access to the entire sub-document. In that case you'll probably want:

$service->elementMap('node', 'Sabre\Xml\Elements\XmlFragment');

If there's another more specific parsing strategy you want, you just have to define your own deserializer:

$service->elementMap('node', function(Sabre\Xml\Reader $reader) {

    // do stuff here and then return.
});

@evert
Copy link
Member

evert commented Sep 13, 2016

Closing this issue, but feel free to follow up and ask more questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants