zoukankan      html  css  js  c++  java
  • FW: DOTNET Quiz 2011 play with XML

    DOTNET Quiz 2011 - play with XML

    Following is the sample XML file named AllBooks.xml for various Computer books published by different publishers alongwith some book details. http://www.wmd-editor.com/


    <?xml version="1.0" encoding="utf-8" ?>
    <AllBooks>
      <Publishers>
        <Publisher PublisherName="MS Press">
          <Books>
            <Book Title="Microsoft SQL Server 2000 DTS Step by Step" Author="Carl Rabeler" Pages="450"></Book>
            <Book Title="Microsoft SQL Server 2005 Integration Services Step by Step" Author="Paul Turleyet" Pages="480"></Book>
            <Book Title="Microsoft SQL Server 2008 Step by Step" Author="Mike Hotek" Pages="800"></Book>       
          </Books>
        </Publisher>

        <Publisher PublisherName="APress">
          <Books>
            <Book Title="SQL Server Security Distilled" Author="Morris Lewis" Pages="352"></Book>
            <Book Title="SQL Server 2008 Query Performance Tuning Distilled" Author="Grant Fritchey" Pages="545"></Book>
          </Books>
        </Publisher>
      </Publishers>
    </AllBooks>

    Assume that in above xml we have unique publishers and Titles per Publisher. You are expected to write a static method called GetBook() with following conditions:

    Programming language must be C#
    Method should accept following three input parameters (1) String strXMLFilePath (2) String strPublisherName (3) String strTitle
    Method should locate a <Book> in AllBooks.xml file as specified by strXMLFilePath on the basis of parameters strPublisherName and strTitle that are passed to it.
    Method must return XmlNode type of object for a <Book> node when the values of parameters strPublisherName and strTitle match to PublisherName and Title respectively for one the books.
    Method must be capable to find corresponding book even if the CASE of values of PublisherName and Title are not maintained when specified. In another words, method must locate the book “SQL Server Security Distilled” even if the value of the passed parameter is “sQl serVer seCuriTy diStilleD”
    Number of statements in GetBook() should be as minimum as possible.
    Use of LINQ is not allowed.
    All participants are requested to provide explanation of code and the approach you have taken.

    static void GetBook(string strXMLFilePath, string strPublisherName, string strTitle)
    {
     XmlDocument xd = new XmlDocument();
     xd.Load(strXMLFilePath);
     XmlNode xn = xd.SelectSingleNode("/AllBooks/Publishers/Publisher[translate(@PublisherName,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + strPublisherName.ToUpper() + "']/Books/Book[translate(@Title,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')='" + strTitle.ToUpper() + "']", null);    
     Console.WriteLine(xn.OuterXml);
    }

  • 相关阅读:
    破解 inode 校园网多网卡限制方法
    更改 eclipse的 workplace路径
    VMware Network Adapter VMnet1和VMnet8 未识别的网络的解决方法
    eclipse更改xml文件,txt文件,property文件等文件编辑器的字体设置
    Lua中数组全排序
    Lua尾调用
    C++ 调用Lua简单例子
    linux生成core dump
    vc获取系统日期
    C++培训第一天
  • 原文地址:https://www.cnblogs.com/aot/p/1925028.html
Copyright © 2011-2022 走看看