I am reading an XML file with a Java project. Everything is alright if the tags are regular i.e. with start tag and end tag. Example:  &lt;Packages&gt;     &lt;Number&gt;20&lt;/Number&gt;     &lt;Marks_one&gt;ONE&lt;/Marks1_one&gt;     &lt;Marks_two&gt;         &lt;null/&gt;     &lt;/Marks_two&gt;     &lt;code&gt;PX&lt;/code&gt;     &lt;name&gt;Pallet &lt;/Kind&gt; &lt;/Packages&gt;   All of the value of these tags can be read including  whice is . But in the same file I have  like this:  &lt;Packages&gt;     &lt;Number/&gt;     &lt;Marks_one&gt;ONE&lt;/Marks1_one&gt;     &lt;Marks_two&gt;         &lt;null/&gt;     &lt;/Marks_two&gt;     &lt;code&gt;PX&lt;/code&gt;     &lt;name&gt;Pallet &lt;/Kind&gt; &lt;/Packages&gt;   Here  is self closing and also doesn't have any attribute. Java is giving exception here and exception is null. I shall omit the tag if it is self closing. Please tell how to find out if that tag is self closing or regular?   Code for parsing XML is given below:  NodeList Packages_List = Item_Element.getElementsByTagName("Packages"); System.out.println("Packages_List.getLength() : "+Packages_List.getLength());Node Packages_Node = Packages_List.item(0);if(Packages_Node.getNodeType() == Node.ELEMENT_NODE){ Element Packages_Element = (Element)Packages_Node;  NodeList Number_of_packages_List = Packages_Element.getElementsByTagName("Number");  Element Number_of_packages_element =(Element)Number_of_packages_List.item(0); NodeList text_Number_of_packages_List = Number_of_packages_element.getChildNodes(); Number=((Node)text_Number_of_packages_List.item(0)).getNodeValue().trim();  System.out.println("Number : "+Number);   }
129
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
97833
I decided to use  as a logger for a new webservice project. Everything is working fine, but I get a lot of messages like the one below, for every log4net tag I am using in my web.config:     Could not find schema information for   the element 'log4net'...   Below are the relevant parts of my web.config:    &lt;configSections&gt;     &lt;section name="log4net"          type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /&gt;   &lt;/configSections&gt;   &lt;log4net&gt;     &lt;appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"&gt;       &lt;file value="C:\log.txt" /&gt;       &lt;appendToFile value="true" /&gt;       &lt;rollingStyle value="Size" /&gt;       &lt;maxSizeRollBackups value="10" /&gt;       &lt;maximumFileSize value="100KB" /&gt;       &lt;staticLogFileName value="true" /&gt;       &lt;layout type="log4net.Layout.PatternLayout"&gt;         &lt;conversionPattern value="%date [%thread] %-5level: %message%newline" /&gt;       &lt;/layout&gt;     &lt;/appender&gt;     &lt;logger name="TIMServerLog"&gt;       &lt;level value="DEBUG" /&gt;       &lt;appender-ref ref="RollingFileAppender" /&gt;     &lt;/logger&gt;   &lt;/log4net&gt;   Solved:   Copy every log4net specific tag to a separate xml-file. Make sure to use .xml as file extension. Add the following line to AssemblyInfo.cs:   [assembly: log4net.Config.XmlConfigurator(ConfigFile = "xmlFile.xml", Watch = true)]    added:     Just a word of warning to anyone   follow the advice of the answers in   this thread. There is a possible   security risk by having the log4net   configuration in an xml off the root   of the web service, as it will be   accessible to anyone by default. Just   be advised if your configuration   contains sensitive data, you may want   to put it else where.     @wcm: I tried using a separate file. I added the following line to AssemblyInfo.cs  [assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]   and put everything dealing with log4net in that file, but I still get the same messages.
49620
I am beginner in automation field, I am trying to automated one of the module, I have tried many different XPATH to fetch proper XPATH for City field o UTest site. Im trying to automate registration module as one of my assignment. I have tried my different xpath example below:  //xpath="//body/div[@class='pac-container pac-logo']/div/span[2]/span" //div[@class='pac-item']/span[3] //div[@class='pac-item']/span //div[@class='pac-container pac-logo']/div/span[2]/../span[3]   the following code written:  //xpath to send data in field @FindBy(xpath="//input[@placeholder='Enter a location']") WebElement city;  //xpath for list to appear @FindBy(xpath="div[@class='pac-item']/span") List&lt;WebElement&gt; City;  public void EnterSignupTwo(String CiTy) throws Exception {     city.clear();     city.sendKeys(CiTy);     Thread.sleep(3000);     System.out.println("the size of List " +City.size());//printing list size      for(int i=0; i&lt;City.size(); i++ ) {         String cities = City.get(i).getText(); //storing list element in String         System.out.println("Converted value of city :"+cities); //print of total list      if(cities.contains(CiTy)) //if parameterized match with Available then click     {         System.out.println("enter specific value of city :"+City.get(i).getText());         City.get(i).click();         break;     } }   kindly refer the
62049
Hello I am trying to find Load # detail from . Also You can  too.  I have tried with xpath: //div[@class='equipment_item']//text()[preceding-sibling::strong[text()='Load #:']][1]    But getting the below error:  org.openqa.selenium.InvalidSelectorException: The given selector //div[@class=' equipment_item']//text()[preceding-sibling::strong[text()='Load #:']][1] is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: The result of the xpath expression "//div[@class=' equipment_item']//text()[preceding-sibling::strong[text()='Load #:']][1]" is: [object Text]. It should be an element. Command duration or timeout: 31 milliseconds
107240
Quite often, in programming we get situations where null checks show up in particularly large numbers. I'm talking about things like:  if (doc != null) {   if (doc.Element != null)   {     ... and so on   }   else     throw new Exception("Element cannot be null"); } else {   throw new Exception("document cannot be null"); }   Basically, the whole thing turns into an unreadable nightmare, so I'm wondering: is there an easier way to describe what I'm trying to do above? (In addition to null checks, I get things like string.IsNullOrEmpty from time to time.)  Accepted answer: I accepted the answer that has  because the approach described is innovative, and is precisely what I want. Thanks Shawn!
28094
I have a text file, i want to search for tags such as the following:  &lt;category="SpecificDisease"&gt;Type II human complement C2 deficiency&lt;/category&gt; &lt;category="Modifier"&gt;Huntington disease&lt;/category&gt; &lt;category="CompositeMention"&gt;hereditary breast and ovarian cancer&lt;/category&gt; &lt;category="DiseaseClass"&gt;myopathy&lt;/category&gt;   and produce the following  and write them to a new text file.  Type II human complement C2 deficiency Huntington disease hereditary breast and ovarian cancer myopathy
90937
I am making a regex expression in which I only want to match wrong tags like: &lt;p&gt; *some text here, some other tags may be here as well but no ending 'p' tag* &lt;/p&gt;   &lt;P&gt;Affectionately Inscribed &lt;/P&gt;&lt;P&gt;TO &lt;/P&gt;&lt;P&gt;HENRY BULLAR, &lt;/P&gt;&lt;P&gt;(of the western circuit)&lt;P&gt;PREFACE&lt;/P&gt;   In the above same text I want to get the result as  &lt;P&gt;(of the western circuit)&lt;P&gt; and nothing else should be captured. I'm using this but its not working:  &lt;P&gt;[^\(&lt;/P&gt;\)]*&lt;P&gt;   Please help.
116963
Is there any way to access the &lt;compilation /&gt; tag in a web.config file?  I want to check if the "debug" attribute is set to "true" in the file, but I can't seem to figure out how to do it. I've tried using the WebConfigurationManager, but that doesn't seem to allow me to get to the &lt;compilation /&gt; section.  Update:  I know I could easily just load the file like an XML Document and use XPath, but I was hoping there was already something in the framework that would do this for me. It seems like there would be something since there are already ways to get App Settings and Connection Strings.  I've also tried using the WebConfigurationManager.GetSection() method in a few ways:    WebConfigurationManager.GetSection("compilation")// Name of the tag in the file WebConfigurationManager.GetSection("CompilationSection") // Name of the class that I'd expect would be returned by this method WebConfigurationManager.GetSection("system.web") // Parent tag of the 'compilation' tag   All of the above methods return null. I'm assuming there is a way to get to this configuration section since there is a class that already exists ('CompilationSection'), I just can't figure out how to get it.
100467
Python has several ways to parse XML...  I understand the very basics of parsing with SAX.  It functions as a stream parser, with an event-driven API.  I understand the DOM parser also.  It reads the XML into memory and converts it to objects that can be accessed with Python.  Generally speaking, it was easy to choose between the two depending on what you needed to do, memory constraints, performance, etc.  (Hopefully I'm correct so far.)  Since Python 2.5, we also have ElementTree. How does this compare to DOM and SAX? Which is it more similar to? Why is it better than the previous parsers?
7217
I don't see any case where the  tag could be useful (or  for that matter).  are always tagged with a programming language, which is much more pertinent.  Should it be Burninated?
44794
I got this XML file:  &lt;root&gt;     &lt;level1 name="A"&gt;         &lt;level2 name="A1" /&gt;         &lt;level2 name="A2" /&gt;     &lt;/level1&gt;     &lt;level1 name="B"&gt;         &lt;level2 name="B1" /&gt;         &lt;level2 name="B2" /&gt;     &lt;/level1&gt;     &lt;level1 name="C" /&gt; &lt;/root&gt;   Could someone give me a C# code using LINQ, the simplest way to print this result: (Note the extra space if it is a level2 node)  A   A1   A2 B   B1   B2 C   Currently I got this code:  XDocument xdoc = XDocument.Load("data.xml")); var lv1s = from lv1 in xdoc.Descendants("level1")            select lv1.Attribute("name").Value;  foreach (var lv1 in lv1s) {     result.AppendLine(lv1);      var lv2s = from lv2 in xdoc...??? }
27673
I've been lately trying to learn more and generally test Java's serialization for both work and personal projects and I must say that the more I know about it, the less I like it. This may be caused by misinformation though so that's why I'm asking these two things from you all:  1: On byte level, how does serialization know how to match serialized values with some class?  One of my problems right here is that I made a small test with ArrayList containing values "one", "two", "three". After serialization the byte array took 78 bytes which seems awfully lot for such low amount of information(19+3+3+4 bytes). Granted there's bound to be some overhead but this leads to my second question:  2: Can serialization be considered a good method for persisting objects at all? Now obviously if I'd use some homemade XML format the persistence data would be something like this  &lt;object&gt;     &lt;class="java.util.ArrayList"&gt;     &lt;!-- Object array inside Arraylist is called elementData --&gt;     &lt;field name="elementData"&gt;         &lt;value&gt;One&lt;/value&gt;         &lt;value&gt;Two&lt;/value&gt;         &lt;value&gt;Three&lt;/value&gt;     &lt;/field&gt; &lt;/object&gt;   which, like XML in general, is a bit bloated and takes 138 bytes(without whitespaces, that is). The same in JSON could be   {     "java.util.ArrayList": {         "elementData": [             "one",             "two",             "three"         ]     } }   which is 75 bytes so already slightly  smaller than Java's serialization. With these text-based formats it's of course obvious that there has to be a way to represent your basic data as text, numbers or any combination of both.  So to recap, how does serialization work on byte/bit level, when it should be used and when it shouldn't be used and what are real benefits of serialization besides that it comes standard in Java?
12247
I have the following code:  List&lt;MobileElement&gt; messages = driver.findElements (By.id ("body_bubble")); //find all messages MobileElement lastMessage = messages.get (messages.size () - 1); //get last message  // xpath query to check if the message is delivered String xpathDeliveryStatus = ".//*[contains(@resource-id, 'delivered_indicator') or contains(@resource-id, 'read_indicator') or contains(@resource-id, 'sent_indicator')]";  MobileElement deliveryStatus = lastMessage.findElement (By.xpath (xpathDeliveryStatus));   I want to do the same except that I want to find the deliveryStatus variable using explicit wait.  So I want to find the deliveryStatus variable inside the lastMessage variable using  wait.until (ExpectedConditions.visibilityOfElementLocated (By.locator))   How can I do this?  I don't want to do it using one immense Xpath. Besides, I don't even know how to find the last element with the id body_bubble using Xpath, as the number of these elements is not fixed and always changing.  P.S. For example, in Python we can define WebDriverWait with an element in the constructor instead of driver:  WebDriverWait(webelement, self.timeout)  Unfortunately, it does not work in Java.
81633
I am creating a GUI frontend for the Eve Online API in Python.  I have successfully pulled the XML data from their server.  I am trying to grab the value from a node called "name":  from xml.dom.minidom import parse dom = parse("C:\\eve.xml") name = dom.getElementsByTagName('name') print name   This seems to find the node, but the output is below:  [&lt;DOM Element: name at 0x11e6d28&gt;]   How could I get it to print the value of the node?
42305
I need to read smallish (few MB at the most, UTF-8 encoded) XML files, rummage around looking at various elements and attributes, perhaps modify a few and write the XML back out again to disk (preferably with nice, indented formatting).  What would be the best XML parser for my needs?  There are lots to choose from.  Some I'm aware of are:            And of course the one in the JDK (I'm using Java 6).  I'm familiar with Xerces but find it clunky.  Recommendations?
38188
I would like to know how I can get the value of a node with the following paths:   config/global/resources/default_setup/connection/host config/global/resources/default_setup/connection/username config/global/resources/default_setup/connection/password config/global/resources/default_setup/connection/dbname   from the following XML:  &lt;?xml version="1.0"?&gt; &lt;config&gt;     &lt;global&gt;         &lt;install&gt;             &lt;date&gt;&lt;![CDATA[Tue, 11 Dec 2012 12:31:25 +0000]]&gt;&lt;/date&gt;         &lt;/install&gt;         &lt;crypt&gt;             &lt;key&gt;&lt;![CDATA[70e75d7969b900b696785f2f81ecb430]]&gt;&lt;/key&gt;         &lt;/crypt&gt;         &lt;disable_local_modules&gt;false&lt;/disable_local_modules&gt;         &lt;resources&gt;             &lt;db&gt;                 &lt;table_prefix&gt;&lt;![CDATA[]]&gt;&lt;/table_prefix&gt;             &lt;/db&gt;             &lt;default_setup&gt;                 &lt;connection&gt;                     &lt;host&gt;&lt;![CDATA[localhost]]&gt;&lt;/host&gt;                     &lt;username&gt;&lt;![CDATA[root]]&gt;&lt;/username&gt;                     &lt;password&gt;&lt;![CDATA[pass123]]&gt;&lt;/password&gt;                     &lt;dbname&gt;&lt;![CDATA[testdb]]&gt;&lt;/dbname&gt;                     &lt;initStatements&gt;&lt;![CDATA[SET NAMES utf8]]&gt;&lt;/initStatements&gt;                     &lt;model&gt;&lt;![CDATA[mysql4]]&gt;&lt;/model&gt;                     &lt;type&gt;&lt;![CDATA[pdo_mysql]]&gt;&lt;/type&gt;                     &lt;pdoType&gt;&lt;![CDATA[]]&gt;&lt;/pdoType&gt;                     &lt;active&gt;1&lt;/active&gt;                 &lt;/connection&gt;             &lt;/default_setup&gt;         &lt;/resources&gt;         &lt;session_save&gt;&lt;![CDATA[files]]&gt;&lt;/session_save&gt;     &lt;/global&gt;     &lt;admin&gt;         &lt;routers&gt;             &lt;adminhtml&gt;                 &lt;args&gt;                     &lt;frontName&gt;&lt;![CDATA[admin]]&gt;&lt;/frontName&gt;                 &lt;/args&gt;             &lt;/adminhtml&gt;         &lt;/routers&gt;     &lt;/admin&gt; &lt;/config&gt;   Also I want to assign that value to the variable for further use. Let me know your idea.
35156
I have an XDocument object. I want to query for elements with a particular name at any depth using LINQ. When I use Descendants(&quot;element_name&quot;), I only get elements that are direct children of the current level. I'm looking for the equivalent of &quot;//element_name&quot; in XPath...should I just use XPath, or is there a way to do it using LINQ methods?