CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Aug 2005
    Posts
    1

    Post transform xml tag to css tag in c#

    Hi there,
    the question is related to C# and XML.

    I have simple xml file
    <pre:book>
    <pre:author> Mark Twain </pre:author>
    <pre:title>Tom Sawyer</pre:title>
    <pre:chapter>text stuff
    <pre:highlight>important stuff</pre:highlight>
    more ordinary text
    </pre:chapter>
    </pre:book>

    I have to parse this file and store its elements into database.
    In C# I used XmlTextReader because of it's processing speed. There is a part of my code:

    XmlTextReader reader = new XmlTextReader(xmlPath);
    while (reader.Read()){
    if(reader.NodeType == XmlNodeType.Element){
    //Get the name of the XML token
    switch (reader.Name.ToLower()){
    case "pre:author":
    saveToDatabase("author",reader.ReadString());
    break;
    case "pre:title":
    saveToDatabase("title",reader.ReadString());
    break;
    ....


    In the database I have a column named 'chapter' to store the text from element <chapter>. But I can not use reader.ReadString() method to read text in the element chapter, bacause it reads just to the first <highlight> element. I need method that will change tags <highlight> to <span class="highlight"> inside element <chapter>. The purpose of this trasformation is the ability to get easily "chapter" information from the database and put it on the web using css styles.
    I suppose I need to use XSLT transformation (I'm new to xml/xslt) Is there a way to do such a transformation for one node
    (<chapter>) on the fly. Or do I need to do the transformation of the whole xml file and after this step to do parsing?

    I appreciate any help.
    Last edited by kolesnik; August 28th, 2005 at 01:18 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured