Problem in obtaining the root XML element. (without prefix)

Hi all

my xml is as below.

< ns1:abcd >
< ns2: a > 1 < / ns2: a >
< ns2:b > 2 < / ns2:b >
< / ns1:abcd >

If I try to retrieve the value of the root of the xml document.

Myroot node = doc.getDocumentElement ();

String result = myroot.getNodeName ();

My output is ns1:abcd... I want only 'abcd '...

Also if I try to print myroot.getPrefix, myroot.getNamespaceURI... all these values are null.

My xml will not always have the same namespaces... starting from the xml inbound I must first check for namespaces... Please give me an idea.

I think so.. I need an evaluation space names to...

Please help me in this regard.

Thank you
Sabarisri. N

Hi Sabarisri,

Please try the following code:

import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;

public class Runner2 {
    public static void main(String[] args) {
        String xmlString =
            "" +
            "  1" +
            "  2" +
            "";

        try {
            InputSource is = new InputSource(new StringReader(xmlString));
            DocumentBuilder docBuilder =
                DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document document = docBuilder.parse(is);
            Element element = document.getDocumentElement();
            System.out.println(element.getLocalName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Kind regards
Pino

Tags: Java

Similar Questions

  • Check for the existing XML element

    Hi all

    I'm writing a simple script first check if an XML element exists and creating so if it's not. I tried to change a piece of code that I used previously to do the same for paragraph styles, but apparently it's not that simple. Currently, all I get is the error "Unable to run the script in the 'main' target engine!" Without checking them, adding the XML element based on the result of the search works very well.

    /* Find all instances of the word "Superscript" */
    app.findTextPreferences.findWhat = "Superscript";
    var mySuperscript = myDocument.findText(); // Save search result for future reference
    
    /* See if an XML element named "Superscript" already exists, and create it if that's not the case; then add it to all instances of the word "Superscript" */
    var myXMLElementSuper = myDocument.xmlElements.item("Superscript");
    try {
    var myName = myXMLElementSuper.name;
    }
    catch (myError){
        var myXMLElementSuper = myDocument.xmlElements.add({markupTag:"Superscript", xmlContent:mySuperscript[i]});}
    

    Any help would be greatly appreciated!

    Regards and thanks in advance.

    Julian

    The myDocument.xmlElements always has a single element - the root element.

    If you want your element directly below that, you have to work a level down.

    To try-catch for such situations regular aid is bad because you spend so usually the ESTK option stop on exceptions and real problems don't miss. Use the isValid property.

    var rootXE = myDocument.xmlElements.item(0);
    var superXE = rootXE.xmlElements.itemByName("Superscript");
    if( !superXE.isValid )
      superXE = rootXE.xmlElements.add(...
    else
     superXE = superXE.getElements()[0]; // take first of potentially multiple elements
    
  • Problem with obtaining the value of availability

    Hello

    I use HQ API in my program in eclipse to collect values for the various indicators of AVAILABILITY of certain resources and it works! But sometimes, the problem is that the values are equal to 1.0, 0.0 sometimes, or even 2.0. I read in the forum that when the value of the availability of a resource is equal to 1.0 at the time t, the resource is available at that time and when it is equal to 0.0 is that it is not available, but I do not understand how the value of availability is equal to 2.0!
    Is my reasoning fair? If this is not the case, what should I do to find the correct values of availability?
    Here are some of my code:

    getting the list of value for a measure with id = idMetric, start = start time and end = end time
    ...
    listValues = hq.getMetricApi () .getMetricData (idMetric, start, end) .getMetricData () .getDataPoint ();

    get the last value

    int size = 0;
    value of type double = 0.0;
    Size = listValues.Size ();
    value = listValues.get (Size-1). GetValue();

    test
    System.out.println (value);

    If (value is 1.0)
    System.out.println ("resource is available at the time:" + end);

    on the other
    System.out.println ("resource is not available at the time:" + end);

    Thanks for helping me to find a solution because it's very urgent.

    Post edited by: kamisan

    Post edited by: kamisan

    The availability of 2.0 means that the value is unknown.
    This is what causes the gray (as opposed to the green/red/yellow) indicator in the table of health resource.

    Thank you wschlichter:
    http://communities.VMware.com/message/1942176#1942176

  • How to change the portlet.xml deployed without redeploying it?

    I often need to change the portlet.xml in deployed war file. But after changing the portlet.xml seeking Middle_Home, he did not have any change to the portlet. Then must I redeploy the war file if I want to change? Or is there another method?

    Kind regards
    Jugela

    Hello.

    Any change in the portlet.xml require a re - deploy application. Load only the configuration such as web.xml files, portlet.xml when the application starts.

    Kind regards.

  • Problem by querying the Excel XML spreadsheet (namespace)

    Hello

    I have a file of Excel (2003) recorded as XML spreadsheet that I wish I could query in the database (10 gr 2) using extract/extractvalue. Somehow, the definition of this file namespace is preventing me from reading the values in the file. The excerpt/extractvalue function returns empty values (NULL). Can someone help me with an example how to query individual nodes in this file?

    Here is the query/XML:
    WITH x AS
         (SELECT HTTPURITYPE ('http://www.dataliberation.nl/newnxl/docs/F2083/xmltestsheet.xml').getxml () xmldoc
          FROM   dual)
    select  extract(xmldoc,'/Workbook/DocumentProperties','xmlns="urn:schemas-microsoft-com:office:office"') doc_properties
    ,       extractValue(xmldoc, '/Workbook/DocumentProperties/Author')      author
    from   x
    Thanks in advance,
    Christian

    I originally written/tested on 11.1.0.6, but I just it ran cleanly on 10.2.0.4 as well.

  • match of XQuery to get an element without prefix

    Hello

    Im trying to replace my body using a xquery to OSB query. The answer I get of a route to another service (which replaces the $body) returns an xml document with the first 2 elements with any of the prefixes:
    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
       <s:Body>
          <UpdateStatusResponse xmlns="http://tempuri.org/">
             <UpdateStatusResult xmlns:b="http://schemas.datacontract.org/2004/07/ROCServiceLibrary" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <b:Messages>
                   <b:Code>XED112</b:Code>
                   <b:Detail>Published</b:Detail>
                </b:Messages>
             </UpdateStatusResult>
          </UpdateStatusResponse>
       </s:Body>
    </s:Envelope>
    The XQuery that I use is:
    <ser:UpdateStatusResponse>
         <roc:Messages>
              <roc:Message>
                   <roc:Code>{data($body/UpdateStatusResponse/UpdateStatusResult/b:Messages/b:Code)}</roc:Code>
                   <roc:Description>{data($body/UpdateStatusResponse/UpdateStatusResult/b:Messages/b:Detail)}</roc:Description>
              </roc:Message>
         </roc:Messages>
    </ser:UpdateStatusResponse>
    But my Code and the Description field will be empty. I added the 2 namespaces (http://tempuri.org/ and http://schemas.datacontract.org/2004/07/ROCServiceLibrary) in the right side of the expression builder. Is this the cause of the response not having not prefixes? Can someone tell me how to get data from the elements that do not have prefixes?

    Best regards!

    define a new prefix to http://tempuri.org/ namespace in xquery say tm, then use the following code

    {data ($body / tm:UpdateStatusResponse/tm:UpdateStatusResult/b:Messages/b:Code)})}
                   {data ($body / tm:UpdateStatusResponse/tm:UpdateStatusResult/b:Messages/b:Detail)})}

  • Problem turning on the Satellite Pro S500 without battery

    Hello!

    I have the following situation with my Satellite Pro S500-115:

    The battery seems to be faulty now (it loads more and Win 7 Pro told me to replace it).
    When I turn on the laptop and the battery is connected, it works for a few minutes and then it suddenly off.

    But even if I remove the battery and the laptop connected to the DC IN, when I press the turn on button have nothing happens!

    If the laptop should not be able to operate in such circumstances, which is only connected to the electric network and with the connected battery off? I have to set in order to operate like this?

    Thanks in advance!

    > The battery seems to be broken now (it loads more and Win 7 Pro told me to replace it).
    > When I turn on the laptop and the battery is connected, it works for a few minutes and then it suddenly off.

    My old laptop battery is dead too much 6 years It's possible to use the laptop in the dough mode for just two minutes after the battery is empty, but I use the notebook with the AC adapter connected and that is why I don't need to replace the battery.

    > Shouldn't the laptop be able to operate in such circumstances, that is only connected to the electric network and with the battery connected off? I have to set in order to operate like this?

    Usually the laptop should be able to turn on and operate without battery connected.
    My laptop works fine with an adapter connected only. So what to say maybe the ESF is also affected, but it's just a suggestion

    But you must check if the BIOS is in place to this day... sometimes a BIOS update could solve some problems of power and battery.

  • Disable the 12 Photoshop elements without a computer

    Hello

    I got two licenses of 12 elements. I was able to install it on four different computers. This PC is damaged at the same time, and I couldn't disable items.

    Now, I would like to install 12 elements once again, but during the installation I get the message, that serialnumbers are not allowed to install (because they seem to be already active).

    How can I disable this?

    All the best

    Frank

    Contact Adobe directly.

    Use the chat here:

    Contact the customer service

  • Add some "BOLD" text to the paragraph XML element

    I try to get the following result:

    < book > < p > now < "BOLD" > Hello Brown < / bold > cow < /p > < / book >

    That's what I have:

    var tagRoot = new XML ("< book >");

    p. tagRoot [0] [0] = "Hello now."

    .bold .p [0] tagRoot [0] = "brown";

    tagRoot [0] [0] of .p += "cow";

    Alert (tagRoot)

    For some reason, it transforms the supports of the "BOLD" tag in HTML entities.

    How can I get the above output?

    Thank you

    Kurtis

    var tagRoot = new XML("");
    tagRoot[0].p[0] = "hello now";
    tagRoot[0].p[0].bold = "brown";
    tagRoot[0].p[0].appendChild (" cow");
    alert(tagRoot.toXMLString())
    

    tagRoot [0] [0] of .p += 'cow' will first convert the content of the

    tag chain, then add the word "cow", then assign the new content channel to the

    tag.

  • Menu widget problem, after obtaining the last menutab you cannot back

    Hello.

    I had a problem with my menu.
    This site http://phinofilm.com/

    When you click on the menubuttons everthing is fine until you click on "Kontakt" (last) then you are stuck on this page and can't get anywhere.

    What should I do?

    Hi Martin

    It seems that you have removed the Menu style that now if I check the site, Menu is not boxed more.

    I was talking to the form that is inserted into the contact page, the framework of the contact form was going on the menu items which was idle.

    Go back the changes, and then check the setting of the contact form, try to balance that, down.

    Thank you

    Sanjit

  • Problem with obtaining the installation for CS5 files

    My computer crashed and I lost photoshop CS5.  How can I reinstall the CS5?

    CS5 download products<---Official link.="">

  • How to obtain the page to an XML element?

    Hi all

    I am fairly new to InDesign scripting (and scripts in general) and have lots of fun :-)

    I have an InDesign document containing several frames (texts, graphics, etc.) and I tagged using the InDesign tags window.

    After much struggle, I managed to get the name of the XML element tag first in my document using this simple code:

    app.activeDocument.xmlElements[0].xmlElements[0].markupTag.name
    

    I know that it worked because I got the right answer in the Javascript console. (By the way, can someone explain to me why I write xmlElements [0] twice?) And what is the difference between xmlElements and xmlItems? Any help is appreciated).

    Then I'll probably use a loop for for each markupTag of each xmlElement. But I have a lot of trouble to obtain the page associated xmlElement :-/

    After a lot of searching on Google, I came across this article which is supposed to answer my question exactly. I tried to understand this code, copy and paste in ExtendScript, but I must admit it's a bit too complex for me...

    Can someone tell me how to get a graphic or a text linked to my XML tags block? Any help is greatly appreciated!

    Nevermind, I found an easier way to achieve what I was trying to do. Actually, I wanted to be able to handle different images in my document, so why I wanted to use the XML markup.

    For those of you who have the same problem, who knows from InDesign CS5, there is an itemByName method that allows you to select an image by its name in the layers panel. So much easier to use :-)

    Thread closed!

  • Root element is missing. System.Xml.XmlException: The root element is missing.

    Hello

    I have .NET 3.5 Web service hosted in my machine (Windows XP SP3) DEV .net 3.5 sp1... When I try to access the service form my

    client is the exception as below...

    Root element is missing. System.Xml.XmlException: The root element is missing.
    at System.Xml.XmlTextReaderImpl.Throw (Exception e)
    at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo (String res)
    at System.Xml.XmlTextReaderImpl.ParseDocumentContent)
    at System.Xml.XmlTextReaderImpl.Read)
    to System.Xml.XmlTextReader.Read)
    at System.Xml.XmlReader.MoveToContent)
    at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse (SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
    at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke (String methodName, Object [] parameters)

    Can any one opinion on this issue... Am I missing any software update...

    Thanks in advance...

    Kind regards

    Richard Starck M.

    Hi RAMANSELVA,

    Your question is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the IT audience Pro on MSDN. Please post your question in the MSDN forum.

    http://social.msdn.Microsoft.com/forums/en-us/netfxsetup/threads

  • Problem with emulator no config.xml file found in the root of the file .zip Blackberry 10 ripple

    I just started development for blackberry 10. I had developed application in the native language. But with blackberry 10 I get "no config.xml file were found at the root of the .zip file" when I run my Hello World application on emulator of the ripple.

    Help is appreciated thanks.

    Here what I got on emulator ripple

    Here's my Helloworld project structure

    Your config.xml file is probably invalid.

    Copy and paste it into this XML validator. http://www.w3schools.com/XML/xml_validator.asp

    If there is a training error will not be able to correctly parse.

  • How to get several xml elements in a relationship 1: n without using xmlaggregation

    I need to create the following xml structure from an oracle database

    where each survey can multiple deelnemers (participants)

    I'm not sure create this use of XMLElement without getting the message "ORA-01427 subquery returns more then one line."

    I could try to use dbms_xmldom (never done that before) but I wonder if anyone knows how to generate this just using the plain Oracle SQL-XMLfunctions (XMLElement, XMLAggr)

    < NieuweSurveys >

    < survey >

    < Surveynaam > 2013 - 02 - 01 < / Surveynaam >

    < Months > 2013 - 02 - 01 < / months >

    < Einddatum > 2013 - 02 - 15 < / Einddatum >

    < Deelnemer >

    Tilde < Chairwoman > < / Chairwoman >

    < Tussenvoegsel / >

    DeelnemerA < Achternaam > < / Achternaam >

    man < Geslacht > < / Geslacht >

    < Emailadres > [email protected] < / Emailadres >

    < Voorkeurstaal > nl < / Voorkeurstaal >

    Schouten < account > & Nelisen < / account >

    bouwer < function > < / function >

    < / Deelnemer >

    < Deelnemer >

    Tilde < Chairwoman > < / Chairwoman >

    < Tussenvoegsel / >

    DeelnemerB < Achternaam > < / Achternaam >

    Vrouw < Geslacht > < / Geslacht >

    < Emailadres > [email protected] < / Emailadres >

    < Voorkeurstaal > nl < / Voorkeurstaal >

    Schouten < account > & Nelisen < / account >

    Tester of < function > < / function >

    < / Deelnemer >

    < / inquiry >

    < / NieuweSurveys >

    What is your version of the database? (SELECT * FROM version$ v)

    The query does not match the output that you claim that it produces.

    In any case, the problem is the following:

    ) as "deelnemers.

    Put an alias here should not generate an element - unless you are using XMLForest in your actual query without your telling us.

    That's why I ask about the version of db, it could be an old bug that's been fixed now (I have not to reproduce the behavior on 11.2).

    What happens when you delete the alias?

Maybe you are looking for

  • Firefox Sync

    HelloI've updated to Firefox. I was using the old version of [email protected] https://support.Mozilla.org/en-us/KB/how-to-update-to-the-new-Firefox-syncOn this page the way which you said. But he did not. How can I get my data.I think that it do

  • Laptops Z61

    Can someone tell me if Win 2000 is compatible with the dual core systems? Thank you!!

  • Sharing of Variable error-1950679023 in LabVIEW 8.6.1

    Hello Is anyone else having problems with this error after installing LabVIEW 8.6.1? Programs using variables shared that I wrote (and worked), just in older versions don't seem to work. Kind regards Sarah

  • I receive windows update error code 646 on two important updates for windows 7.

    I tried to update manually, nothing helps. My windows update icon remains with the same updates, and he tells me that updates could not be installed. Help, please. the updates in question are 981433 KB and KB 981715. I don't know what to do. Need hel

  • Cannot find the corrupt configuration file to be recovered.

    I had a similar problem to many people, with my computer telling me that the windows\system32\config\system file is corrupted missing. But after trying the steps on the support page, I got no further than the first step that the files that I need to