PHP - Need Help With Domxpath
so i am trying to make my api for a website, and started coding a script for it.
so far it looks like this
<?php
Similar TutorialsHey all long time no post lol so im working on improving this RosterAPI Josh Grochowski made and im adapting it for use with a nother site my issue is this i have to get data from an html file the data i wana collect in nested like this Code: [Select] <div class="talentcalc-info"> <div class="third-party"> <a href="javascript:;" data-fansite="talentcalc|paladin|000000000000000000003202322312112110022000000000000000000000" class="fansite-link "> </a> </div> <div class="export" style="display: none"><a href="#">Export</a></div> <div class="calcmode"><a href="javascript:;">Calculator mode</a></div> <div class="restore" style="display: none"><a href="javascript:;">Restore</a></div> <div class="reset" style="display: none"><a href="javascript:;">Reset</a></div> <div class="pointsspent" style="display: none"><span class="name">Points spent:</span><span class="value"><span>0</span><ins>/</ins><span>30</span><ins>/</ins><span>0</span></span></div> <div class="pointsleft" style="display: none"><span class="name">Points left:</span><span class="value">0</span></div> <div class="requiredlevel" style="display: none"><span class="name">Required level:</span><span class="value">-</span></div> </div> being that "talentcalc|paladin|000000000000000000003202322312112110022000000000000000000000" is the data i wana retrive i have tryed Code: [Select] query('.//div[@class="talentcalc-info"]/div[@class="third-party"]/a');but im getting no where fast any ideas guys? Hi, I've been tearing my hair out over this problem for hours (and I've precious little left as it is). It's hopefully just a 'wood for the trees' moment. I'm trying to parse XML search results using DOMDocument and DOMXPath, the problem is that the DOMDocument never seems to get populated. I can load the XML result set via cURL fine, and the XML validates ok. Here's my code: $xmldoc = new DOMDocument(); $xmldoc->load( 'http://searchserver/xml.cgi?collection=test&query=' ); $xpath = new DOMXPath( $xmldoc ); $results = $xpath->query( "/padre_result_packet" ); echo '<pre>'; print_r( $results ); echo '</pre>'; And here's an example of the XML I'm working with: Code: [Select] <?xml version="1.0" encoding="iso-8859-1" standalone="no" ?> <PADRE_result_packet> <details> <padre_version>Unknown</padre_version> </details> <error> <usermsg>Please specify a valid query</usermsg> <adminmsg>The query parameter is invalid or missing</adminmsg> </error> </PADRE_result_packet> The result is: Code: [Select] DOMNodeList Object ( ) Does anybody have some advice? I was getting the following error when using $xmldoc->loadXML: Code: [Select] Warning: DOMDocument::loadXML(): Start tag expected, '<' not found in Entity, line: 1 Hello All,
I have searched these forums and the net but haven't found an exact answer. I have a "path" (could be paths) that is/are causing warnings as it/they is/are poorly formed. This is bloating our logs, therefore I need to alleviate the issue. There are thousands of paths in the database so I do not know which are causing issues. I know I can add the "@" to the call to quiet the warning. First question: does that keep the warning from going into the logs?
I would prefer not to use the method above as it bypasses the real issue. Looking at the SimpleXMLElement documentation along with DOMDocument and DOMXPAth, I can't find a way to validate the actual path. All of the below throw a warning or notice: $xpath->evaluate($path); $xpath->query($path); $node->xpath($path); Final question: Is there a "simple" way to validate the $path prior to actually making the call to one of the methods of the various XML PHP classes?
Thank you for your time and assistance. Edited November 5, 2020 by oach |