Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14215

Re: Extracting values from xml file using php/xpath/namespace/simplexml/

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Extracting values from xml file using php/xpath/namespace/simplexml/
Date 2014-09-05 08:24 -0400
Organization A noiseless patient Spider
Message-ID <luca25$o9o$1@dont-email.me> (permalink)
References (8 earlier) <lu8ao0$ha6$1@dont-email.me> <2974602.zgg0cvazeg@PointedEars.de> <lub0uq$8cj$1@dont-email.me> <lub5tu$k7f$3@solani.org> <lub8dn$glf$2@dont-email.me>

Show all headers | View raw


On 9/4/2014 10:50 PM, Denis McMahon wrote:
> On Fri, 05 Sep 2014 04:08:09 +0200, Christoph M. Becker wrote:
> 
>> Jerry Stuckle wrote:
>>
>>> On 9/4/2014 5:21 PM, Thomas 'Pointed Head' Lahn wrote:
>>>> Jerry Stuckle wrote:
>>
>>> His code will detect the change in the markup.  Yours will not, because
>>> you are not using the full XPath.  And once again - yours can fail if
>>> the XML happens to have multiple (but different) XPaths with the same
>>> identifiers.  The Ops will not.
>>
>> "Mutitple (but different) XPaths"?  Do you mean multiple (but different)
>> XPath expressions?
> 
> No
> 
> Jerry is trying to point out to tpel-troll that if you use a partial xpath 
> instead of a fully qualified xpath to match data in an xml document, 
> there is a risk that if the same partial xpath matches one or more 
> unwanted elements as well as the wanted element(s), the unwanted element
> (s) will end up as part of the selection.
> 
> Hence, Jerry is suggesting that it is better from the start to use the 
> fully qualified xpath and namespace, because in Jerry's opinion (whether 
> you agree with it or not) having an obvious error or empty dataset is 
> better than having a dataset that contains incorrect data.
> 
> You may or may not agree with Jerry on that last point, I happen to think 
> he's got a very valid point - that it's better to know something's gone 
> wrong with the selection process than to end up with an invalid dataset 
> and blithely carry on processing it as if it was valid.
> 
> As an example, if you were closing out unclaimed bank accounts of 
> deceased people and giving the money to the state, it would be bad to 
> accidentally select some accounts of non-deceased people because someone 
> changed the xml source data and your code didn't handle the change.
> 
>>>>> That is generally NOT the case in XML - which is why each element has
>>>>> an identity as well as a value.
>>>>
>>>> Nonsense.
>>>>  
>>> Now I KNOW you don't have any idea how XML works!
>>
>> You have claimed that "each XML element has a value", what is utter
>> nonsense.
> 
> Be careful that you don't get caught out on the meanings of words as used 
> by other people. In my understanding, every xml element has a value, that 
> value being the content of the element, which may be null.
> 
> For example, in the document:
> 
> <? xml version="1.0" encoding="utf-8" standalone="yes" ?>
> <things>
> <thing />
> <thing>
> <type>instrument</type>
> <name>kettle drum</name>
> </thing>
> <thing>
> <type>instrument</type>
> <name>trombone</name>
> <owner>
> <id>x5432</id>
> </owner>
> </thing>
> <thing>
> <type>vehicle</type>
> <name>car</name>
> <owner>
> <id>x5432</id>
> </owner>
> </thing>
> </things>
> 
> The value of the first "thing" is null
> 
>>> You haven't seen the entire code.  They can easily detect if XPath
>>> changes, as I indicated above.
>>
>> "XPath changes"?
> 
> I think Jerry meant if the xml changes.
> 
> For example, If I change the previous document to add an id element for 
> instruments and a name element for owners, then there might be a problem 
> with xpath that just selected name or id elements without fully 
> qualifying them such that all names would now contain people names as 
> well as instrument names, and all ids would now include instrument ids as 
> well as people ids. A fully qualified selector looking for instrument 
> owner ids would only select ids that were a child of owner that was a 
> child of instrument, rather than any id, just as a fully qualify 
> qualified instrument name selector would only select a name that was a 
> child of an instrument item, rather than selecting any name (including, 
> perhaps, the names of vehicles).
> 
> eg consider "//name" vs "//instrument//name" vs "/things/thing/instrument/
> name" as xpath applied to the above document. Then consider what happens 
> in each case if the upstream generator changes the document and a 'name' 
> child element is added to the 'owner' elements.
> 
>>> As I indicated before - different XPaths, but same identity.  Once
>>> again you have proven you know nothing about XML.
>>
>> "Different XPaths"?
> 
> Again, I think Jerry is referring to the potential for an upstream change 
> in the xml leading to cases where the xpath, if not fully qualified, 
> might return an incorrect dataset. And I still think his basic premise is 
> right, especially as I often work with xml datasets whose generation is 
> wholly outside of my control. If the upstream changes the dataset, I'd 
> prefer my application to fail gracefully having detected that the dataset 
> has changed rather than soldier blithely on and possibly generate 
> incorrect results as a result of my xpath selectors pulling out an 
> incorrect selection.
> 

Thank you, Denis.  You and I have similar approaches on good programming
practices.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Extracting values from  xml file using php/xpath/namespace/simplexml/ ofuuzo@gmail.com - 2014-08-13 04:02 -0700
  Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-08-13 09:25 -0400
    Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ ofuuzo@gmail.com - 2014-08-14 03:29 -0700
      Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-08-14 10:06 -0400
      Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-08-17 19:43 +0200
        Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-08-17 15:21 -0400
          Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-08-17 23:41 +0200
            Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-08-17 18:57 -0400
              Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-09-03 23:10 +0200
                Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-09-03 20:11 -0400
                Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-09-04 02:42 +0200
                Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-09-03 21:57 -0400
                Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-09-04 23:21 +0200
                Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-09-04 20:43 -0400
                Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-09-05 04:08 +0200
                Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Denis McMahon <denismfmcmahon@gmail.com> - 2014-09-05 02:50 +0000
                Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-09-05 08:24 -0400
                Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-09-07 11:57 +0200
                Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ Jerry Stuckle <jstucklex@attglobal.net> - 2014-09-07 09:54 -0400
                Re: Extracting values from  xml file using php/xpath/namespace/simplexml/ "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2014-09-07 23:53 +0200

csiph-web