Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: What is the best way to parse a xml file without xmlns?

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    31
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default What is the best way to parse a xml file without xmlns?

    For reason beyond my control, I must parse a xml without xmlns tag. I believe that it is a bad practice because it miss namespace control. Anyway, I must program for such scenario. What could be the best way to face it? I try setNamespaceAware = false and it does work for file without xmlns tag but it seems that it doesn't work properly when reading xml with xmlns tag. Plus this, I guess that by setting any awareness configuration to false isn't a good practice. I read some article telling to add the xmlns to the file but I am in doubt if it might be a good option (How to add Namespaces programmatically to the XML parser ? (XML forum at JavaRanch)). Any comment will be appreciated.

    javax.xml.parsers.DocumentBuilderFactory fac = new org.apache.xerces.jaxp.DocumentBuilderFactoryImpl();
    fac.setNamespaceAware(true);
    org.w3c.dom.Document d = null;
    javax.xml.parsers.DocumentBuilder builder = fac.newDocumentBuilder();
    d = builder.parse("C:/my_folder/my_file.xml");
     
     
    <?xml version="1.0" encoding="UTF-8"?>
    <c:de format="N" lengthField="0" maxLength="012" minLength="012" name="AMOUNT, TRANSACTION" number="004" subFields="00"/>

    There is a question I posted before that is related to this subject but with very different question (http://www.javaprogrammingforums.com...tml#post148402).

    P.s.: I posted the same question in other forum (http://stackoverflow.com/questions/2...-without-xmlns)
    Last edited by DemeCarv; May 26th, 2014 at 04:47 PM.


Similar Threads

  1. How to parse an object to and from XML using JAXB
    By Json in forum File Input/Output Tutorials
    Replies: 1
    Last Post: August 8th, 2013, 05:45 PM
  2. How to parse an XML having same tag.
    By 1bun100 in forum File I/O & Other I/O Streams
    Replies: 12
    Last Post: February 24th, 2012, 08:34 AM
  3. How to parse an object to and from XML using JAXB
    By Json in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: January 20th, 2010, 03:42 AM
  4. How to read an XML document in Java with DOM Parse?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 0
    Last Post: May 20th, 2008, 07:04 AM
  5. How to read an XML document in Java with DOM Parse?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: May 20th, 2008, 07:04 AM

Tags for this Thread