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);
    }

  • 相关阅读:
    Bootstrap_让Bootstrap轮播插件carousel支持左右滑动手势的三种方法
    JAVA_用Java来获取访问者真实的IP地址
    Html5_移动前端不得不了解的html5 head 头标签
    ThinkPad_T430重装系统
    JavaScript_JS判断客户端是否是iOS或者Android
    Html5_禁止Html5在手机上屏幕页面缩放
    HttpClient_httpclient 4.3.1 post get的工具类
    HttpClient_使用httpclient必须知道的参数设置及代码写法、存在的风险
    LATEX数学公式基本语法
    为WLW开发Latex公式插件
  • 原文地址:https://www.cnblogs.com/aot/p/1925028.html
Copyright © 2011-2022 走看看