XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 26th, 2004, 09:10 AM
Derek720HT Derek720HT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 Derek720HT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
java.net.MalformedURLException: no protocol

Anyone here run into this Exception? I've got an XML document that I can parse fine when reading it from a file. I'm trying to set something up where I receive the encoded contents of the doc through a request parameter in a .jsp. When I try to parse the contents I get a java.net.MalformedURLException: no protocol. Seems kind of obscure since my XML isn't referring to any other documents.

Reply With Quote
  #2  
Old April 1st, 2004, 02:23 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 13
Send a message via AIM to bricker42
You can't parse an xml string using the same method that you use to parse an xml file. If you try using the same method java will try to interpret the xml string as a url and you will get the error you're seeing.

If you're working with xml in java I'd recommend using dom4j. It's fast and has the easiest to use API that I've found. It has a DocumentHelper.parse() function that will take an xml string and return a Document. If you use straight JAXP I think you'll need to wrap the xml string in a StringReader.
__________________
-james

Reply With Quote
  #3  
Old February 25th, 2005, 04:06 PM
bcaverly bcaverly is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 1 bcaverly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 58 sec
Reputation Power: 0
Send a message via Yahoo to bcaverly
more MalformedURLException problems

Quote:
Originally Posted by bricker42
You can't parse an xml string using the same method that you use to parse an xml file. If you try using the same method java will try to interpret the xml string as a url and you will get the error you're seeing.

If you're working with xml in java I'd recommend using dom4j. It's fast and has the easiest to use API that I've found. It has a DocumentHelper.parse() function that will take an xml string and return a Document. If you use straight JAXP I think you'll need to wrap the xml string in a StringReader.


I'm having a similar (I think) problem. I have written an XSLT which works fine using it in XMLSpy 2005 when the source XML is in a local file along with the DTD file (ops.dtd) in the same directory. However, the problem is that I will actually receive the XML in a J2EE application as a string parsed from an HTTP response. When I try to transform the XML string (see below) I get "java.net.MalformedURLException: no protocol"

XML Listing:
Code:
<?xml version='1.0' encoding="UTF-8" standalone="no" ?>
<!DOCTYPE OPS_envelope SYSTEM "ops.dtd">
<OPS_envelope>
<header>
<version>0.9</version>
</header>
<body>
<data_block>
<dt_assoc>
	<item key="object">DOMAIN</item>
	<item key="attributes">
	 <dt_assoc>
	 <item key="status">available</item>
	 <item key="match"></item>
	 </dt_assoc>
	</item>
	<item key="response_text">Domain available</item>
	<item key="is_success">1</item>
	<item key="response_code">210</item>
	<item key="protocol">XCP</item>
	<item key="action">REPLY</item>
</dt_assoc>
</data_block>
</body>
</OPS_envelope>


If I modify the XML string so that the DTD URI is "file:C:/Projects/TUCOWS/ops.dtd" (my local absolute path to a copy of the dtd) then all is well - my transformation works and execution proceeds as expected. However, I consider this "fix" to be a less than desirable hack since what I really want is a way to either tell the parser loaded by the xalan transformer not to validate (so it won't need or care about the DTD) or a better way to specify where to find the DTD. I am using the xercesImpl-2.1.0.jar and using the following "locally grown" methods to do the transform:

Code:
	public static String transformString(String xmlString, String xslURL) throws XMLServerException
	{
		StreamSource xmlSource = null;
		StreamSource xslSource = null;
		try
		{
			xmlSource = new StreamSource(new StringReader(xmlString) );
			xslSource = new StreamSource(new URL(xslURL).openStream());
			return transformReader(xmlSource, xslSource);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		return null;
	}
	protected static String transformReader(StreamSource xmlSource, StreamSource xslSource) throws XMLServerException
	{
		StringWriter out = new StringWriter();
		try
		{
			TransformerFactory tFactory = TransformerFactory.newInstance();
			Transformer transformer = tFactory.newTransformer(xslSource);
			transformer.transform(xmlSource, new StreamResult(out));
		}
		catch (TransformerFactoryConfigurationError tfce)
		{
			tfce.printStackTrace();
			throw new XMLServerException(XMLServerException.TRANSFORMER_CONFIGURATION,
				"Transformation Configuration exception: " + tfce.toString());
		}
		catch (TransformerException e)
		{
			e.printStackTrace();
			throw new XMLServerException(XMLServerException.TRANSFORMATION,
				"Transformation exception: " + e.toString());
		}
		return out.toString();
	}


The XML in the listing above is the first argument to transformString(), the second argument is the local absolute URL to the following XSLT:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:xs="http://www.w3.org/2001/XMLSchema" 
	xmlns:dns="http://www.hns.com/iag/framework/xml/tucows/domainsrvc" 
	xmlns="http://www.hns.com/iag/framework/xml/tucows/domainsrvc/lookup" 
	exclude-result-prefixes="xs">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<!-- ~~~~~~~~~~~~~~~~~~ LookupDomainResponseMsg ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<xsl:template match="/OPS_envelope">
	<LookupDomainResponseMsg>
	 <xsl:attribute name="xsi:schemaLocation">http://www.hns.com/iag/framework/xml/tucows/domainsrvc/lookup C:/Projects/TUCOWS/domainsrvc_lookup.xsd</xsl:attribute>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
	 <responseHeader>
		<xsl:for-each select="body">
		 <xsl:for-each select="data_block">
			<xsl:for-each select="dt_assoc">
			 <xsl:for-each select="item">
				<xsl:choose>
				 <xsl:when test="@key = 'object'">
					<object>
					 <xsl:value-of select="."/>
					</object>
				 </xsl:when>
				 <xsl:when test="@key = 'protocol'">
					<protocol>
					 <xsl:value-of select="."/>
					</protocol>
				 </xsl:when>
				 <xsl:when test="@key = 'action'">
					<action>
					 <xsl:value-of select="."/>
					</action>
				 </xsl:when>
				 <xsl:when test="@key = 'response_code'">
					<responseCode>
					 <xsl:value-of select="."/>
					</responseCode>
				 </xsl:when>
				 <xsl:when test="@key = 'response_text'">
					<responseText>
					 <xsl:value-of select="."/>
					</responseText>
				 </xsl:when>
				 <xsl:when test="@key = 'is_success'">
					<isSuccess>
					 <xsl:value-of select="."/>
					</isSuccess>
				 </xsl:when>
				</xsl:choose>
			 </xsl:for-each>
			</xsl:for-each>
		 </xsl:for-each>
		</xsl:for-each>
	 </responseHeader>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
	 <responseAttributes>
		<xsl:for-each select="body">
		 <xsl:for-each select="data_block">
			<xsl:for-each select="dt_assoc">
			 <xsl:for-each select="item">
				<xsl:if test="@key = 'attributes'">
				 <xsl:for-each select="dt_assoc">
					<xsl:for-each select="item">
					 <xsl:choose>
						<xsl:when test="@key = 'status'">
						 <status>
							<xsl:value-of select="."/>
						 </status>
						</xsl:when>
						<xsl:when test="@key = 'price_status'">
						 <priceStatus>
							<xsl:value-of select="."/>
						 </priceStatus>
						</xsl:when>
						<xsl:when test="@key = 'no_service'">
						 <noService>
							<xsl:value-of select="."/>
						 </noService>
						</xsl:when>
					 </xsl:choose>
					</xsl:for-each>
				 </xsl:for-each>
				</xsl:if>
			 </xsl:for-each>
			</xsl:for-each>
		 </xsl:for-each>
		</xsl:for-each>
	 </responseAttributes>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
	</LookupDomainResponseMsg>
</xsl:template>
</xsl:stylesheet>


Thanks in advance for your help!

Bob

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > java.net.MalformedURLException: no protocol

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap