This is what happened at noon today. Someone asked for help in the group. For example, if the xml file is marked as xx: xxxxcontentxx: xxxx, xx: xxxx cannot be taken as the underlying value.
This is what happened at noon today. Someone asked for help in the group. For example, if the xml file is marked as xx: xxxxcontent/xx: xxxx, xx: xxxx cannot be taken as the underlying value.
After reading this question, the first reaction was the relationship between namespace, but I never used simplexml to operate namespace. So I opened the manual and checked the information. The problem was not solved, google eventually solved the problem.
A friend who asked the question posted the data source from: # retrieving_without_query. The data structure is roughly as follows:
The Code is as follows:
Liz@gmail.com
2008-12-10T10: 04: 15.446Z
Elizabeth Bennet's Contacts
Elizabeth Bennet
Liz@gmail.com
Contacts
1
1
25
% 40gmail.com/base/c9012de
2008-12-10T04: 45: 03.331Z
2008-12-10T04: 45: 03.331Z
Fitzwilliam Darcy
Fitzwilliam Darcy
456
This structure is shown in the preceding address. This is the XML data that I have formatted. 456 .
The final code is as follows:
The Code is as follows:
$ X = new SimpleXmlElement ($ str );
Foreach ($ x-> entry as $ t ){
Echo $ t-> id ."
";
Echo $ t-> updated ."
";
$ Namespaces = $ t-> getNameSpaces (true );
$ Gd = $ t-> children ($ namespaces ['gd ']);
Echo $ gd-> phoneNumber;
}
Of course, the server space, the Hong Kong server, and the U.S. server can also be written as follows if it is not as described above:
The Code is as follows:
$ X = new SimpleXmlElement ($ str );
Foreach ($ x-> entry as $ t ){
Echo $ t-> id ."
";
Echo $ t-> updated ."
";
// $ Namespaces = $ t-> getNameSpaces (true );
// Note the difference between this and the above section
$ Gd = $ t-> children ('HTTP: // schemas.google.com/g/2005 ');
Echo $ gd-> phoneNumber;
}
Just like the second method, it is hard-coded. This is not good. In case of any change, you have to change N more codes.
The problem arises one after another, such as the following section:
The Code is as follows:
Learn QB in Minutes
9
02/12/2009
02/12/2009
11
30
NOT_INPROGRESS
PUBLIC
This non-standard XML does not define a namespace. What should I do? In this case, SimpleXmlElement can be solved directly, but it will report warnging because he thinks the namespace event does not exist.
Solution:
The Code is as follows:
$ Xml = @ new SimpleXmlElement ($ str); // Add @ to the front to stop the error.
Echo"
";
Print_r ($ xml );
Currently, this solution is better.
PHP SimpleXML Functions
PHP SimpleXML