Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

XmlTransform validate on parse

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
seigo - 15 Nov 2006 13:46 GMT
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
Martin Honnen - 15 Nov 2006 14:08 GMT
> Xml document contains the following namespace:
>
> <Primetime_Screening
> xmlns="http://www.medicalhistory.com/PrimetimeScreening" ..>

You need to write your XPath expressions and XSLT match patterns the
proper way to match/select elements in the default namespace:
<http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

seigo - 15 Nov 2006 14:59 GMT
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 написав:

> > Xml document contains the following namespace:
> >
[quoted text clipped - 4 lines]
> proper way to match/select elements in the default namespace:
> <http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>
Martin Honnen - 15 Nov 2006 17:21 GMT
> 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

>> <http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

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.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.