DOM W3c XML Element Parsing Null Attribute

Multi tool use
Multi tool use












0















I am parsing some data from XML using DOM in this format:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FEFExchangeFile>
<program>
<identProgram name="TestSection" type="section" task="MAST"></identProgram>
<FBDSource nbRows="24" nbColumns="36">


The node list of "program" node parses correctly like this:



DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(CodeFile);
NodeList programeNodeList= doc.getElementsByTagName("program");


I get the "program" element in for loop from the nodelist which also works fineas below:



 // Get the current program node element
Element programNode = (Element) programeNodeList.item(i);


Then when I get to get the first item "identProgram" in the "program" element it works fine like this and I can pick up the attributes into a string:



 // Get the IdentProgram node element from Program node
Element identProgramElement = (Element) programNode.getElementsByTagName("identProgram").item(0);


But what has got me stumped. In the exact same code as above that I use for getting the "identProgram" I use to get the next item after that "fbdSource" but it is giving me a null pointer exception:



 // Get the FbdSource element from Program node 
Element fBDSourceElement = (Element) programNode.getElementsByTagName("FBDSource").item(0);


As stated the code used to get the identProgram and the fbdSource are the same. They are at the same level in the xml. Not sure what would cause this.



Thanks










share|improve this question




















  • 1





    The first step is to determine which reference is null. Unfortunately, we won't be able to be much help without a Minimal, Complete, and Verifiable example and the full error (stack trace).

    – Slaw
    Jan 1 at 5:16








  • 1





    please provide the xml content and error clearly

    – Rathnayake
    Jan 1 at 17:31
















0















I am parsing some data from XML using DOM in this format:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FEFExchangeFile>
<program>
<identProgram name="TestSection" type="section" task="MAST"></identProgram>
<FBDSource nbRows="24" nbColumns="36">


The node list of "program" node parses correctly like this:



DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(CodeFile);
NodeList programeNodeList= doc.getElementsByTagName("program");


I get the "program" element in for loop from the nodelist which also works fineas below:



 // Get the current program node element
Element programNode = (Element) programeNodeList.item(i);


Then when I get to get the first item "identProgram" in the "program" element it works fine like this and I can pick up the attributes into a string:



 // Get the IdentProgram node element from Program node
Element identProgramElement = (Element) programNode.getElementsByTagName("identProgram").item(0);


But what has got me stumped. In the exact same code as above that I use for getting the "identProgram" I use to get the next item after that "fbdSource" but it is giving me a null pointer exception:



 // Get the FbdSource element from Program node 
Element fBDSourceElement = (Element) programNode.getElementsByTagName("FBDSource").item(0);


As stated the code used to get the identProgram and the fbdSource are the same. They are at the same level in the xml. Not sure what would cause this.



Thanks










share|improve this question




















  • 1





    The first step is to determine which reference is null. Unfortunately, we won't be able to be much help without a Minimal, Complete, and Verifiable example and the full error (stack trace).

    – Slaw
    Jan 1 at 5:16








  • 1





    please provide the xml content and error clearly

    – Rathnayake
    Jan 1 at 17:31














0












0








0








I am parsing some data from XML using DOM in this format:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FEFExchangeFile>
<program>
<identProgram name="TestSection" type="section" task="MAST"></identProgram>
<FBDSource nbRows="24" nbColumns="36">


The node list of "program" node parses correctly like this:



DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(CodeFile);
NodeList programeNodeList= doc.getElementsByTagName("program");


I get the "program" element in for loop from the nodelist which also works fineas below:



 // Get the current program node element
Element programNode = (Element) programeNodeList.item(i);


Then when I get to get the first item "identProgram" in the "program" element it works fine like this and I can pick up the attributes into a string:



 // Get the IdentProgram node element from Program node
Element identProgramElement = (Element) programNode.getElementsByTagName("identProgram").item(0);


But what has got me stumped. In the exact same code as above that I use for getting the "identProgram" I use to get the next item after that "fbdSource" but it is giving me a null pointer exception:



 // Get the FbdSource element from Program node 
Element fBDSourceElement = (Element) programNode.getElementsByTagName("FBDSource").item(0);


As stated the code used to get the identProgram and the fbdSource are the same. They are at the same level in the xml. Not sure what would cause this.



Thanks










share|improve this question
















I am parsing some data from XML using DOM in this format:



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<FEFExchangeFile>
<program>
<identProgram name="TestSection" type="section" task="MAST"></identProgram>
<FBDSource nbRows="24" nbColumns="36">


The node list of "program" node parses correctly like this:



DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(CodeFile);
NodeList programeNodeList= doc.getElementsByTagName("program");


I get the "program" element in for loop from the nodelist which also works fineas below:



 // Get the current program node element
Element programNode = (Element) programeNodeList.item(i);


Then when I get to get the first item "identProgram" in the "program" element it works fine like this and I can pick up the attributes into a string:



 // Get the IdentProgram node element from Program node
Element identProgramElement = (Element) programNode.getElementsByTagName("identProgram").item(0);


But what has got me stumped. In the exact same code as above that I use for getting the "identProgram" I use to get the next item after that "fbdSource" but it is giving me a null pointer exception:



 // Get the FbdSource element from Program node 
Element fBDSourceElement = (Element) programNode.getElementsByTagName("FBDSource").item(0);


As stated the code used to get the identProgram and the fbdSource are the same. They are at the same level in the xml. Not sure what would cause this.



Thanks







java xml dom nullpointerexception






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 5:06







Nicholas Muir

















asked Jan 1 at 4:59









Nicholas MuirNicholas Muir

79411533




79411533








  • 1





    The first step is to determine which reference is null. Unfortunately, we won't be able to be much help without a Minimal, Complete, and Verifiable example and the full error (stack trace).

    – Slaw
    Jan 1 at 5:16








  • 1





    please provide the xml content and error clearly

    – Rathnayake
    Jan 1 at 17:31














  • 1





    The first step is to determine which reference is null. Unfortunately, we won't be able to be much help without a Minimal, Complete, and Verifiable example and the full error (stack trace).

    – Slaw
    Jan 1 at 5:16








  • 1





    please provide the xml content and error clearly

    – Rathnayake
    Jan 1 at 17:31








1




1





The first step is to determine which reference is null. Unfortunately, we won't be able to be much help without a Minimal, Complete, and Verifiable example and the full error (stack trace).

– Slaw
Jan 1 at 5:16







The first step is to determine which reference is null. Unfortunately, we won't be able to be much help without a Minimal, Complete, and Verifiable example and the full error (stack trace).

– Slaw
Jan 1 at 5:16






1




1





please provide the xml content and error clearly

– Rathnayake
Jan 1 at 17:31





please provide the xml content and error clearly

– Rathnayake
Jan 1 at 17:31












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993106%2fdom-w3c-xml-element-parsing-null-attribute%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993106%2fdom-w3c-xml-element-parsing-null-attribute%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







uK1i WQP5TAUQbqBpEMkLCtasZXl2x56fGgkx
KJotZ0ODi6p,2GLPvM W4,tvC,70X,Uq4LXb4abITBpEkbd158IRnTS411V4W YiA,RDkL7ZV Y18 sbbqSq4XO6K

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas