Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 2nd, 2009, 08:06 AM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML request format issue

Hi All,

I am trying to convert dom to string, I have check my code and found every thing is fine in my code, My function is returning good value

But i found that after converting from Dom tree to string when i am passing to Request Node using "<xsl:value-of select="$Request"/>" xml parser is giving following error

***Failure*** javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: Element type "RootNode" must be followed by either attribute specifications, ">" or "/>".
This is not happening always ... when i am firing 100's of request this is happening once ot twice.


Following is my code


Java Function:

public static String domToString(Node node) throws Throwable
{
TransformerFactory f;
try {
f = TransformerFactory.newInstance();

Transformer t = f.newTransformer();

StringWriter answer = new StringWriter(5000);
t.transform(new DOMSource(node), new StreamResult(answer));
return answer.toString();
}
catch (Throwable ex)
{
throw ex;
}
}

-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------

XSL:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="Request">
<xsl:value-of select="Temp:domToString(RootNode)" xmlns:Temp="MyUtilPkg.DU"/>
</xsl:variable>


<xsl:template match="Context">

<TempRQ>
<Request>
<xsl:value-of select="$Request"/>
</Request>
</TempRQ>

</xsl:template>
<xsl:template match="text()"></xsl:template>
</xsl:stylesheet>

-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------

Context:

<?xml version="1.0"?>
<Context>
<RootNode>
<RQ>
<Session_Info>
<User_ID>TestOperator</User_ID>
<Session_ID>123456789</Session_ID>
<Password>TestOperator</Password>
<Terminal_ID>71005244</Terminal_ID>
</Session_Info>
<Customer_Info>
<Name>
<FirstName></FirstName>
<LastName></LastName>
<Type></Type>
<MI></MI>
<Suffix></Suffix>
<MaternalName></MaternalName>
<PaternalName></PaternalName>
</Name>
<Address>
<StreetAddress></StreetAddress>
<Address2></Address2>
<City></City>
<State></State>
<NumericStateCode></NumericStateCode>
<ZipCode></ZipCode>
<Country></Country>
<Phone></Phone>
<WorkPhone></WorkPhone>
</Address>
<CustomerCode></CustomerCode>
</Customer_Info>
</RQ>
</RootNode>
</Context>
 
Old September 5th, 2009, 02:18 AM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi ... please help .. i am not able to resolve this issue
 
Old September 5th, 2009, 04:18 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Does changing it to this help:

<xsl:value-of select="Temp:domToString(/Context/RootNode)" xmlns:Temp="MyUtilPkg.DU"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old September 7th, 2009, 01:54 AM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Sam,

I tried this but it is not working, actually there is no problem in my function,
I have checked the output of function when error is coming. i am getting that error after passing the value of variable to xml

<TempRQ>
<Request>
<xsl:value-of select="$Request"/>
</Request>
</TempRQ>

Actually what i am doing that i am first creating domtostring then i am creating on Asynchronous thread and passing request TempRQ and in new thred i am again converting it to stringtodom at that time it is giving error.


I debug and found that after converting dom to string, when i am resolving varible value at that time my xml parser (I am using Xalan and Xerces) is again serlizing or parsing the string and at time i am geeting the error

***Failure*** javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: Element type "RootNode" must be followed by either attribute specifications, ">" or "/>".

And This is not happening always ... when i am firing 100's of request this is happening once or twice.
 
Old September 7th, 2009, 02:46 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well if it is only happening sometimes, and not every time, then it is obviously some race condition or something specific to either your code or the java code. Definitely looks like a threading issue though doesn't it. So I'm afraid I don't think I can help any further as I'm not actually a java developer.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old September 7th, 2009, 03:10 AM
Authorized User
 
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Sam for your help,

But i have check my java code and there is no problem in it, whenever i am getting error I checked the output of java code and it is fine.

I think the problem is with Xalan and Xerces, I guess this is due to firing same request simultaneously from different thread.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating XML doc ; writing string(xml format) into KamalRaturi XML 5 May 28th, 2008 05:51 AM
Data Format Issue---need help please zone Excel VBA 0 August 13th, 2007 04:21 PM
apply xsl format to an xmlhttp request darkhalf XSLT 5 September 5th, 2006 08:34 AM
send XML Request and get XML Response prashant_dnmmkpk VB.NET 2 February 25th, 2005 03:34 PM
Request("var") issue cmiller Classic ASP Basics 1 May 21st, 2004 10:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.