× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




Hi James,

<snip>
Parsing what comes back without an XML parser isn't as hard as it may
seem, either; all you have to do is scan for the tags delimiting the
data that's of interest, and ignore the rest.
<snip>

just as a qualification:

I would consider this statement to be true only if you can guarantee the XML element to be found is uniquely named, and the unique name will exist in one and only one XPath location. Even with these guarantees you have to consider that other XML elements may have a name that begins with this name and this element may/may not have attributes. These two combined can cause false positives:

<root>
<MyElement>myData</MyElement>
<MySubElement>
<MyElement attribute="Value">MySubData</MyElement>
<MyElement2>My other data</MyElement2>
</MySubElement>
<MySubElement>
<MyElement>MySubData2</MyElement>
<MyElement2>My other data2</MyElement2>
</MySubElement>
</root>

We want the content of all instances of /root/MySubElement/MyElement

Searching for '<MyElement>' will find only one instance - the second one, but will also find /root/MyElement.
Taking into account the attribute on the first instance of /root/MySubElement/MyElement we could search for '<MyElement', but this will find /root/MyElement, /root/MySubElement/MyElement, and /root/MySubElement/MyElement2.
Searching for '<MyElement ' will not find the second instance of /root/MySubElement/MyElement because it has no attributes.
Searching for 'MyElement' is no allowed as it may occur within text data.

For custom parsing like this I believe it is better to use a tried-and-tested parser such as xml-into. xml-into will also check for well-formedness, which a hand-rolled custom parser will not.

Introducing namespaces to differentiate between the two MyElement nodes may help, but is definitely an inappropriate use. In fact, adhoc introduction of a namespace could cause a custom parse to fail when a standard parser succeeds. This would also be true for xml-into because it is not namespace aware.
Just some further thoughts.

Cheers

Larry Ducie



_________________________________________________________________
If It Exists, You'll Find it on SEEK Australia's #1 job site
http://clk.atdmt.com/NMN/go/157639755/direct/01/

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.