• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Consuming Remote XML
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Consuming Remote XML


  • Subject: Re: Consuming Remote XML
  • From: Kieran Kelleher <email@hidden>
  • Date: Fri, 20 Aug 2010 22:48:43 -0400

OK, this is my third attempt to send this reply to the mailing list!
___________________________________________________________

I have used  apache's xerces library's SAX parser for this in the past........

Attached is a SAX handler straight from a working project and below is some code snippets that use it....... I have not touched this code for a long long time, so I hope you can understand it......

<snip>
	/**
	 * @param response
	 * @return a dictionary of results
	 */
	protected NSDictionary<String, String> parseResponse(Reader responseReader) {
		XMLReader reader = WKXMLUtilities.createXMLReader();
		SatoriZipTaskSaxHandler handler = new SatoriZipTaskSaxHandler();
		reader.setContentHandler(handler);
		InputSource inputSource = null;

		if (log.isDebugEnabled()) {
			String response;
			try {
				response = WKIOUtilities.read(responseReader);
				log.debug("Satori Response = \n" + response);
				StringReader sr = new StringReader(response);
				inputSource = new InputSource(sr);
			} catch (IOException e) {
				throw new NestableRuntimeException(e);
			}

		} else {
			// Regular logic
			inputSource = new InputSource(responseReader);
		} //~ if (log.isDebugEnabled())
		// Convert responseReader into an InputSource


		try {
			reader.parse(inputSource);
		} catch (IOException e) {
			throw new NestableRuntimeException(e);
		} catch (SAXException e) {
			throw new NestableRuntimeException(e);
		}

		NSDictionary<String, String> results = handler.results();

		return results;
	}
</snip>

<snip>
package wk.webobjects.xml;

import org.apache.commons.lang.exception.NestableRuntimeException;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

public class WKXMLUtilities {
	public static XMLReader createXMLReader() {
		try {
			return XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
		} catch (SAXException e) {
			throw new NestableRuntimeException(e);
		}
	}
}
</snip>

Attachment: SatoriZipTaskSaxHandler.java
Description: Binary data


Hope this gives you some starting points,

Regards, Kieran


On Aug 20, 2010, at 7:07 PM, Ken - Watermark Studios wrote:

> So, with PHP I can use either Curl or SimpleXML to consume remote XML files, then I can navigate and parse the XML files with XPath. I have a web service that transmits simple XML objects (no WSDL). How can I consume and parse with WO? I also know how to consume a local domain XML file with JQuery as well, but the cross-domain policy keeps me from doing so with JQuery.
>
> Thanks,
>
> Ken _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Consuming Remote XML (From: Ken - Watermark Studios <email@hidden>)

  • Prev by Date: This is a test.....
  • Next by Date: Re: Consuming Remote XML
  • Previous by thread: Re: Consuming Remote XML
  • Next by thread: This is a test.....
  • Index(es):
    • Date
    • Thread