 |
| 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
|
|
|
|

September 2nd, 2009, 08:06 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

September 5th, 2009, 02:18 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi ... please help .. i am not able to resolve this issue
|
|

September 5th, 2009, 04:18 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Does changing it to this help:
<xsl:value-of select="Temp:domToString(/Context/RootNode)" xmlns:Temp="MyUtilPkg.DU"/>
|
|

September 7th, 2009, 01:54 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

September 7th, 2009, 02:46 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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.
|
|

September 7th, 2009, 03:10 AM
|
|
Authorized User
|
|
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |