SimpleXML or DOMDocument help
SimpleXML or DOMDocument help
am 09.12.2009 20:02:38 von Michael Alaimo
Hello All,
I have an XML document that has elements as such:
Test/Query:Equal>
I cannot figure out how to access these with simple xml. I am not opposed
to a DOMDocument solution either.
Would anyone know what to do in this case? I think the problem is the :.
Regards,
Mike
*************************************
Michael Alaimo
ADNET Systems, Inc.
Web Developer
Work: 301-286-5569
Cell: 571-332-9210
*************************************
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: SimpleXML or DOMDocument help
am 09.12.2009 20:31:05 von Shawn McKenzie
Michael Alaimo wrote:
> Hello All,
>
> I have an XML document that has elements as such:
>
>
> Test/Query:Equal>
>
>
>
>
> I cannot figure out how to access these with simple xml. I am not opposed
> to a DOMDocument solution either.
>
> Would anyone know what to do in this case? I think the problem is the :.
>
> Regards,
>
> Mike
>
>
>
>
> *************************************
> Michael Alaimo
> ADNET Systems, Inc.
> Web Developer
> Work: 301-286-5569
> Cell: 571-332-9210
> *************************************
>
>
What's the entire XML document? You need a xmlns declaration as Query
is a namespace.
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: SimpleXML or DOMDocument help
am 09.12.2009 21:21:55 von Shawn McKenzie
Please keep this on list.
The URI for the namespace is important. Something like (not tested):
| ||// use URI for Query namespace|
| foreach ($xml->children('http://www.example.com/something') as $Query) {
echo $Query->Where;
}
||
|
Michael Alaimo wrote:
>> What's the entire XML document? You need a xmlns declaration as Query
>> is a namespace.
>>
> The document is valid XML. xml_parse_into_struct returns an array with
> all of the values. Its just so much work to get it to work.
>
> SimpleXML wont let me access $xml->Query->{Query:Where}. for example
>
>
>> --
>> Thanks!
>> -Shawn
>> http://www.spidean.com
>>
>>
>>
>
>
>
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: SimpleXML or DOMDocument help
am 09.12.2009 21:28:16 von Shawn McKenzie
Shawn McKenzie wrote:
> Please keep this on list.
>
> The URI for the namespace is important. Something like (not tested):
>
> | ||// use URI for Query namespace|
> | foreach ($xml->children('http://www.example.com/something') as $Query) {
> echo $Query->Where;
> }
> ||
> |
> Michael Alaimo wrote:
>>> What's the entire XML document? You need a xmlns declaration as Query
>>> is a namespace.
>>>
>> The document is valid XML. xml_parse_into_struct returns an array with
>> all of the values. Its just so much work to get it to work.
>>
>> SimpleXML wont let me access $xml->Query->{Query:Where}. for example
>>
>>
>>> --
>>> Thanks!
>>> -Shawn
>>> http://www.spidean.com
Wow, that came out with some weird pipes in it:
// use URI for Query namespace
foreach ($xml->children('http://www.example.com/something') as $Query) {
echo $Query->Where;
}
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: SimpleXML or DOMDocument help
am 09.12.2009 21:46:39 von Shawn McKenzie
Shawn McKenzie wrote:
> Shawn McKenzie wrote:
>> Please keep this on list.
>>
>> The URI for the namespace is important. Something like (not tested):
>>
>> | ||// use URI for Query namespace|
>> | foreach ($xml->children('http://www.example.com/something') as $Query) {
>> echo $Query->Where;
>> }
>> ||
>> |
>> Michael Alaimo wrote:
>>>> What's the entire XML document? You need a xmlns declaration as Query
>>>> is a namespace.
>>>>
>>> The document is valid XML. xml_parse_into_struct returns an array with
>>> all of the values. Its just so much work to get it to work.
>>>
>>> SimpleXML wont let me access $xml->Query->{Query:Where}. for example
>>>
>>>
>>>> --
>>>> Thanks!
>>>> -Shawn
>>>> http://www.spidean.com
>
> Wow, that came out with some weird pipes in it:
>
> // use URI for Query namespace
> foreach ($xml->children('http://www.example.com/something') as $Query) {
> echo $Query->Where;
> }
>
I guess you could also use (not tested):
$ns = $xml->getNamespaces(true);
foreach ($xml->children($ns['Query']) as $Query) {
echo $Query->Where;
}
Maybe look at the xpath() method, I don't know anything about it.
--
Thanks!
-Shawn
http://www.spidean.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: SimpleXML or DOMDocument help
am 10.12.2009 01:46:58 von Michael Peters
Shawn McKenzie wrote:
> Michael Alaimo wrote:
>> Hello All,
>>
>> I have an XML document that has elements as such:
>>
>>
>> Test/Query:Equal>
>>
>>
>>
>>
>> I cannot figure out how to access these with simple xml. I am not opposed
>> to a DOMDocument solution either.
>>
>> Would anyone know what to do in this case? I think the problem is the :.
>>
>> Regards,
>>
>> Mike
>>
>>
>
> What's the entire XML document? You need a xmlns declaration as Query
> is a namespace.
>
I have run into documents that use a namespace without properly defining it.
Seems fairly common in data sets from academic sources (IE vertebrate
museum records). Usually there is only one namespace, and you can use a
regular expression to just remove it before importing the document.
IE -
$buffer = preg_replace('/Query:/','',$input);
then import the $buffer
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: SimpleXML or DOMDocument help
am 10.12.2009 14:23:05 von Michael Alaimo
> Michael Alaimo wrote:
>> Hello All,
>>
>> I have an XML document that has elements as such:
>>
>>
>> Test/Query:Equal>
>>
>>
>>
>>
>> I cannot figure out how to access these with simple xml. I am not
>> opposed
>> to a DOMDocument solution either.
>>
>> Would anyone know what to do in this case? I think the problem is the
>> :.
>>
>> Regards,
>>
>> Mike
>>
>>
>
> What's the entire XML document? You need a xmlns declaration as Query
> is a namespace.
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
>
I was able to solve this by using
$ns = $xml->getNamespaces(true);
foreach ($xml->children($ns['Query']) as $Query) {
echo $Query->Where;
}
Thanks for the help Shawn.
Mike
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php