From: Stefan Behnel on
Martin v. Loewis, 16.05.2010 09:07:
>> the approach that the OP is apparently trying to follow is
>> clearly misguided.
>
> I completely agree. However, I recommend that we let him find out on his
> own. I suspect he has some idiomatic usage of XML, perhaps with all
> namespace prefixes defined in the root element. He'll find out that his
> approach is flawed in the general case when he encounters such a case.
> It's probably pointless trying to convince him in the abstract.

Probably, yes. It's just that I prefer it if broken code doesn't get
written in the first place, rather than having to fix it later on, which in
this case even seems to imply breaking a user visible feature. But you're
right, let's leave the decision to the OP.

Stefan

From: Martin v. Loewis on
> Maybe true technically, but false in practice. If I receive XML data
> from source XYZ or service XYZ the use of namespaces and their prefixes
> is extremely consistent [in practice] and very customary (for example:
> I've never seen the DSML namespace abbreviated as anything other than
> "dsml" and I rarely see WebDAV propfind XML use a namespace prefix other
> than "D"). The odds that a customer or vendors ERP will generate
> different namespaces and abbreviations between requests is ludicrously
> remote [I don't recall ever seeing it happen].

In that case, you could also hard-code all prefixes in your application;
no need to traverse the input document.

Regards,
Martin
From: Stefan Behnel on
Martin v. Loewis, 16.05.2010 11:05:
>> Maybe true technically, but false in practice. If I receive XML data
>> from source XYZ or service XYZ the use of namespaces and their prefixes
>> is extremely consistent [in practice] and very customary (for example:
>> I've never seen the DSML namespace abbreviated as anything other than
>> "dsml" and I rarely see WebDAV propfind XML use a namespace prefix other
>> than "D"). The odds that a customer or vendors ERP will generate
>> different namespaces and abbreviations between requests is ludicrously
>> remote [I don't recall ever seeing it happen].
>
> In that case, you could also hard-code all prefixes in your application;
> no need to traverse the input document.

+1. Hard-coding the prefixes is the best way to make the interface of your
code consistent and predictable.

Stefan