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

  • 相关阅读:
    367 Valid Perfect Square 有效的完全平方数
    365 Water and Jug Problem 水壶问题
    363 Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K
    357 Count Numbers with Unique Digits 计算各个位数不同的数字个数
    SpringBoot (四) :thymeleaf 使用详解
    SpringBoot(三) :Spring boot 中 Redis 的使用
    SpringBoot(二) :web综合开发
    SpringBoot (一) :入门篇
    程序员最核心的竞争力是什么?
    Java面试题:多继承
  • 原文地址:https://www.cnblogs.com/aot/p/1925028.html
Copyright © 2011-2022 走看看