XmlTransform validate on parse

  • Thread starter Thread starter seigo
  • Start date Start date
S

seigo

Hi there,

I use the following code to transform xml to html document:

try
{
XPathDocument myXPathDoc = new XPathDocument(sXmlPath);
XslTransform myXslTrans = new XslTransform();
myXslTrans.Load(sXslPath);

//create the output stream
XmlTextWriter myWriter = new XmlTextWriter("result.html", null);

//do the actual transform of Xml

myXslTrans.Transform(myXPathDoc, null, myWriter, null);

myWriter.Close();
}
catch(Exception e)
{
Console.WriteLine("Exception: {0}", e.ToString());
}

Xml document contains the following namespace:

<Primetime_Screening
xmlns="http://www.medicalhistory.com/PrimetimeScreening" ..>

When this namespace exists there is no data from xml document. And
after I remove such xmlns transformation works fine. I think something
with validation. If I am right how to disable validation during xml
transformation or maybe it's better to remove that namespace from the
xml document and then processing it.

Thanks for any ideas!
Alexander Kleshchevnikov
www.klalex.com
 
Hi Martin,

Thanks, I know the problem now. But how can I change my code? Or do I
need to change xsl document? How, for instance, I can address this
<xsl:value-of
select="/Primetime_Screening/Report/Chief_Complaint/Narrative" />?

Thanks,
Alexander Kleshchevnikov
www.klalex.com

Martin Honnen íàïèñàâ:
 
seigo said:
Thanks, I know the problem now. But how can I change my code? Or do I
need to change xsl document? How, for instance, I can address this
<xsl:value-of
select="/Primetime_Screening/Report/Chief_Complaint/Narrative" />?

Yes, you need to change the stylesheet, as described in

you need to bind a prefix to that namespace URI and use that prefix in
XPath expressions e.g.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ps="http://www.medicalhistory.com/PrimetimeScreening"
version="1.0">

<xsl:template match="/">
<xsl:value-of
select="/ps:Primetime_Screening/ps:Report/ps:Chief_Complaint/ps:Narrative"
/>
</xsl:template>


At least that is what I guess you have to do, you have only shown the
first line of your input XML.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top