-
Notifications
You must be signed in to change notification settings - Fork 79
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
Parsing XML with custom deserializers #124
Comments
did you check the docs? http://sabre.io/xml/reading/ how does your code look like atm? |
@staabm yeah, I did, but the docs all seem to be expecting namespaces (which this response doesn't contain). Here is what I have so far: $service = new Service();
$service->elementMap['response'] = Response::class;
// $service->elementMap['errors'] = Errors::class;
// $service->elementMap['error'] = Error::class;
$ns = 'response';
$body = $service->parse((string) $response->getBody(), null, $ns); // Where $response is the response from Guzzle Then my public static function xmlDeserialize(Reader $reader)
{
$response = new self();
if ($method = $reader->getAttribute('method')) {
$response->method = $method;
}
if ($success = $reader->getAttribute('success')) {
$response->success = strtoupper($success) === 'Y';
}
return $response;
} Nothing else gets parsed from there onwards though. |
how does the for non namespaced classes your clark notation just needs to be like |
|
on the first look I can only see 1 mistake (curly braces missing in your element map): $service = new Service();
$service->elementMap['{}response'] = Response::class; |
Those curly braces didn't seem to do anything, so I left them off. This is what I have now: $service = new Service();
$service->elementMap = [
'{}response' => 'Sabre\Xml\Deserializer\keyValue',
'{}request' => Request::class,
'{}errors' => Errors::class,
'{}error' => Error::class,
];
$ns = 'response';
$body = $service->parse((string) $response->getBody(), null, $ns); Which gives me: array:2 [
"{}errors" => BlueBayTravel\Fusion\Readers\Errors {#834
+errors: array:1 [
0 => BlueBayTravel\Fusion\Readers\Error {#847
+code: null
+text: "Invalid username and/or password."
}
]
}
"{}request" => BlueBayTravel\Fusion\Readers\Request {#839
+auth: null
+method: null
}
] |
So I've managed to get errors to work, just not the request yet. |
Oh and I'd still want to wrap the entire |
they represent the xmlnamespace.
how is the
|
Hey! I've recently found this package and it looks like it'll solve all of my needs, the custom deserializers look perfect for what I'm trying to achieve, I'm just having some difficulty implementing with non-namespaced XML...
I'm trying to parse the following:
What I expect I'd end up with is a custom
Response
reader that contains:method
andsuccess
valuesErrors
reader that'll be array ofError
classes which have mapped thecode
andtext
attributesRequest
reader which does the sameHow can I achieve this? Every time I try to read the result, I either exceed the memory usages or my
Response
reader won't continue to parse the errors or request elements.Thanks for your help!
The text was updated successfully, but these errors were encountered: