Returning Text Nodes
Hi,
Can somebody please help me with this problem. I am trying to return a specific node name, return it, and see if it has any child nodes. Below is a snippet from my XML doc:
<description>
<genre>football simulation</genre>
<year>2004</year>
<publisher ....However, when I enter "year", I am presented with
<year>2004</year>as the child nodes of the "year" node. And when print the results from
getNodeType, the text nodes arent identified. How can I get my code to see if there are text nodes present and return the text nodes?? I'll be extrmely grateful for any help!! Thanks.
Below is some of my Java code:
NodeList docNodes = test.getElementsByTagName("year");
if(docNodes.getLength() !=0){
System.out.println("noelist length: "+docNodes.getLength());
for (int i=0; i<docNodes.getLength();i++){
Node blah = docNodes.item(i);
System.out.println(blah);
System.out.println(blah.getNodeType());
if(blah.hasChildNodes()){
System.out.println("child nodes present: "+blah.getChildNodes());
Node check = (Node) blah.getChildNodes();
System.out.println("node type: "+check.getNodeType());
if (check.getNodeType()==Node.TEXT_NODE){
System.out.println("text nodes present");
else{
System.out.println("text nodes ARENT present");
}
Here is a little helper class I use when parsing DOM via Xerces. May not work equally well for jDOM or other implementations.
final public class XmlHelper extends Object {
// Class Variables //
/** TODO Consider moving this to an interface with constants */
static final public String XML_TAG_ROOT = "document";
// Constructors //
* Default constructor.
public XmlHelper() {
super();
// Static Methods //
static public Document newDocument()
throws ConfigurationException {
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
return builder.newDocument();
catch (ParserConfigurationException configure) {
throw new ConfigurationException("Error instantiating DOM XML parser", configure);
static public Document parse(InputStream in)
throws ConfigurationException, IOException, ParseException {
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
return builder.parse(in);
catch (ParserConfigurationException configure) {
throw new ConfigurationException("Error instantiating DOM XML parser", configure);
catch (SAXException parse) {
throw new ParseException("Error SAX parsing XML input stream", parse);
static public Document parse(String uri)
throws ConfigurationException, IOException, ParseException {
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
return builder.parse(uri);
catch (ParserConfigurationException configure) {
throw new ConfigurationException("Error instantiating DOM XML parser", configure);
catch (SAXException parse) {
throw new ParseException("Error SAX parsing XML uri '" + uri + "'", parse);
static public String serialize(Document target)
throws IOException, ConfigurationException, TransformationException {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
serialize(target, byteOut, true);
return byteOut.toString();
static public void serialize(Document document, OutputStream target)
throws IOException, ConfigurationException, TransformationException {
serialize(document, target, false);
static public void serialize(Document document, OutputStream target, boolean indent)
throws IOException, ConfigurationException, TransformationException {
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
if (indent)
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(new DOMSource(document), new StreamResult(target));
catch (TransformerConfigurationException configure) {
throw new ConfigurationException("Error instantiating XML transformer", configure);
catch (TransformerException transform) {
/** @todo Need to write a generic transformation or serialization exception */
throw new TransformationException("Error transforming XML", transform);
static public Element getChildElement(Element parent, String name) {
Element child = null;
if (parent != null) {
NodeList childNodes = parent.getElementsByTagName(name);
switch (childNodes.getLength()) {
case 0:
System.err.println("XML element <" + parent.getNodeName() + ">" +
" has zero child nodes <" + name + "> (expecting one node)");
case 1:
child = (Element) childNodes.item(0);
break;
default:
child = (Element) childNodes.item(0);
/** @todo Consider implementing a "Warning Log" for errors such as these rather than sys.err */
System.err.println("XML element <" + parent.getNodeName() + ">" +
" has " + childNodes.getLength() + " child nodes <" + name + "> (expecting only one)");
return child;
static public List getAllChildElements(Element parent, String name) {
List elements = null;
if (parent != null) {
elements = Collections.synchronizedList(new ArrayList());
NodeList childNodes = parent.getChildNodes();
for (int current = 0; current < childNodes.getLength(); current++) {
Node node = childNodes.item(current);
if ((node instanceof Element) && node.getNodeName().equals(name)) {
elements.add(node);
return elements;
static public String getChildElementValue(Element parent, String childName) {
Element child = getChildElement(parent, childName);
return child == null ? null : getElementValue(child);
static public String getElementValue(Element parent) {
NodeList nodes = parent.getChildNodes();
int current = 0;
int length = nodes.getLength();
while (current < length) {
Node node = nodes.item(current);
if (node instanceof Text) {
String value = node.getNodeValue();
if (value != null)
return value.trim();
current++;
return "";
}- Saish
Similar Messages
-
Carriage Return in Text Node of SmartForm
Hello SAPients.
I'm working with a Text node in a SmartForm. I'm using "Include Text" to call an existing text. The text loads fine except that it doesn't respects the CR's.
What can I do?Hello SAPients!
I'm still having this problem, maybe I didn't explain the problem very well and that's why I didn't get an answer. I hope this information be more helpful:
I'm working in SAP 4.6C. I have a SmartForm with a Text Node that shows "unlimited" text. I created another transaction to maintain this text in a small text editor and save the text using FM SAVE_TEXT and retrieve it using FM READ_TEXT and it shows everything correct.
In the SmartForm I'm taking advantage of the option "Include text" in the Text type of the General Attributes of the text node. The system retrieves the text in a normal way, except that the text is shown without Carriage Return, that is, all the text is show in one single line. Do you know why?
Thank you in advance for your help. -
Reading DOM document text nodes
I have created a DOM document from a text string, which seems fine. The structure is something like:
<BOOK>
<BOOK_ID>1</BOOK_ID>
<BOOK_NAME>Test Book 1</BOOK_NAME>
<BOOK_DESC>This is a test book</BOOK_DESC>
</BOOK>When I try to traverse this structure using DOM, for each node (BOOK_ID, BOOK_NAME, BOOK_DESC), I get two nodes - one ElementNode, one TextNode, as I would expect.
However, when I call get value on the TextNodes, it simply returns "\n ", instead of returning the text between the tags.
Does any one know why?
Thanks a lot,
JimI have some thing similar probelm but failed to get this working. Which ever nodes I try, all I get is node value "null" and say's that the node type is ELEMENT_NODE, but that node is TEXT_NODE as per schema.
So I tried to validate the schema xml file which is external (even the xml file is located external), but failed to get this working too, now just stranded wihtout any clues what I have to do.
I am using DOM parser with j2sdk-1.4.1_05.
My xml file is:
<?xml version="1.0" standalone="yes" ?>
<IRXML CorpMasterID="9999999">
<NewsRelease ReleaseID="215555" DLU="20020814 15:43:00" ArchiveStatus="Current">
<Title>Viking Energy CEO and CFO Certify Financial Reports for SEC</Title>
<Date Date="20020814" Time="15:32:00">8/14/2002 3:32:00 PM</Date>
<Categories>
<Category>Financial Releases</Category>
</Categories>
</NewsRelease>
</IRXML>
The nodes <Title> and <Date> are text nodes, so any help is appreciated.
Thanks. -
Problems getting text content of text node?
Hi all,
I am currently somewhat puzzled why one of the simplest parts of my code doesn't work. I am trying to get the text content of a text node (XmlValue.getNodeType() correctly returns TEXT_NODE) in Java, but what I get is always the text of the entire document retrieved from the database (no matter what text node I consult in the entire document!). Is this expected behaviour? The method I am using to retrieve the data is XmlValue.getNodeValue(), but playing around with other functions didn't show any success either.
So my question is: what am I doing wrong here? I hope someone in here can help me with my rather stupid problem :-)
Thanks for your help,
AlexHello Rucong,
thanks for your quick answer. I am sorry for the delay - I was away for a couple of days.
I boiled down my code to a simple example - however can't believe it's the query itself (since it's really basic). But maybe you see something I am missing?
Here is my sample code that exhibits this behaviour:
XmlManagerConfig managerConfig = new XmlManagerConfig();
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(false);
envConfig.setInitializeCache(true);
envConfig.setInitializeLocking(false);
envConfig.setInitializeLogging(true);
envConfig.setTransactional(false);
envConfig.setErrorStream(System.out);
Environment env = new Environment(new File("D:\\dbhome"), envConfig);
XmlManager manager = new XmlManager(env, managerConfig);
XmlManager.setLogLevel(XmlManager.LEVEL_ALL, true);
XmlManager.setLogCategory(XmlManager.CATEGORY_ALL, true);
XmlContainerConfig containerConfig = new XmlContainerConfig();
containerConfig.setAllowCreate(true);
XmlContainer container = manager.openContainer("mpeg7samples.dbxml", containerConfig);
XmlQueryContext context = container.getManager().createQueryContext();
String query = "for $a in collection('mpeg7samples.dbxml') return $a";
XmlResults result = container.getManager().query(query, context);
while (result.hasNext()) {
XmlValue v = result.next();
if (v.getNodeType() != XmlValue.DOCUMENT_NODE)
throw new Exception();
v = v.getFirstChild();
if (v.getNodeType() != XmlValue.TEXT_NODE)
throw new Exception();
System.out.println(v.getNodeValue());
break;
container.close();
manager.close();
This code executes a simple query and then dumps the first text node of the first retrieved document. As stated before the System.out.println() call dumps the text of the entire document (including <?xml...?> at the beginning and so on) though.
Any ideas?
Thanks in advance for your help,
Alex -
In SMARTFORMS when openee a Text Node, Giving a Short Dump
Hi
I am getting Short Dump in SMARTFORMS Transaction, when ever I opened a Text Node and made some changes in it.
With out opening a Text Node I can able to change and activate the SmartForm.
But if I open a Text Node I can able to make changes in the Text Node but later if i click on any other Node, it is giving a Short Dump.
But all other systems in my office are working fine.
I have tried the Utilities->Settings-> and changed the editor also.
I have also Installed the SAPGUI once again for this Issue. But still I am getting the same problem.
Can anyone Please help me on this Issue.
I am sending the error enalysis of the Short Dump.
Error analysis
Short text of error message:
Control Framework : Error processing control
Long text of error message:
Diagnosis
An error occurred when the system tried to process the commands
from the Automation Queue on the presentation server.
There are several possible reasons for this:
- The installation of the SAP GUI on the presentation server is
faulty or obsolete.
- There is an error in the application program
- There is an error in the SAPGUI or an integrated control
Procedure
1. Make sure that you have imported the appropriate Support
Package, the current kernel, and GUI patch for the release of your
system
2. Check whether the error occurs locally on one or a few PCs, or
generally on all PCs. Note whether the error only occurs for some
users, for example because of a specific Customizing setting.
If it only occurs locally, this suggests an installation problem
with the PC. Check the installation; if necessary, reinstall the
software. In the dump, search for the SY-MSGLI field, since it may
point to the cause of the error.
3. Activate the Automation Trace (in accordance with SAP Note
158985).
4.Start the transaction and continue until the screen immediately
before the dump.
5. From the System -> Utilities menu, choose Autom. Queue,
Synchronous Processing.
The status bar of the GUI displays the text:
"Automation synchron flush mode on"
6. If you now proceed with the application, the short dump will
display the ABAP call that caused the error; the Automation Trace
will contain the error on the presentation server.
7. If necessary, load the short dump and trace files on to
sapservX, so that SAP can analyze them.
Technical information about the message:
Message class....... "CNDP"
Number.............. 006
Thanks in Advance.Hi
I think dump is because of SAP GUI. If you are ECC 6.0 then install SAP GUI 710 with patch level 2 or more and check
Regards
Shiva -
I am not sure Essbase has the capacity to do this but I figured this would be the place to ask. Can you set a member formula to return text instead of a number? For example, in Excel you can set up an If statement that will return a number or text depending on set variables. Can Essbase do this as well?
We have some calculations that depending on whether certain variables are positive or negative could return a result that really has no meaning. So, if this were to be the case I would like it to return a N/A instead of the number. I can do this in Excel based on data pulled from Essbase but it would be much easier and less to maintain if Essbase was able to do it for me.
ThanksCurrently, Essbase databases can only store and return numbers. You can, however, mark the cell as '#Missing' and thus meaningless data would not be returned. The #Missing cells can have a string label associated with them (on the client if you are using Excel).
Tim Tow
Applied OLAP, Inc -
Text node in the Charac Hierarchy sums up
Hi,
I am working on IP.
I had created an hierarchy for a specific consumption data with the top node as a text node, which should appear only once in the report.
But when i use the Input ready query, the system shows multiple rows of the text node for every new characteristic values in the nodes below this node.
How do i avoid the text node being displayed multiple times?
Thanks in advance,
regards,
SriramHi Jacky,
Yes i have text nodes for more than one set of characteristics.
Level 1A
Level 2
Char1 A
Char1 B
Level 1B
Char1 C
Char1 D
Char1 E
These characteristic also have an attribute characteristic. Hence, in the Input ready query it displays as follows;
Level 1A
Level 2 Char2 A
Level 2 Char2 B
Char1 A Char2 A
Char1 B Char2 B
Is there a way to avoid the "Char2" in the text nodes.
Thank in advance for the solution,
regards,
Sriram -
Text node not showing first line?
I'm trying to figure out some unexpected behavior with the layout of Text. If I create an example program based on the API documentation
http://java.sun.com/javafx/1.2/docs/api/javafx.scene.text/javafx.scene.text.Text.html
Like so:
Stage
title: "Application title"
width: 500
height: 500
scene: Scene
content: [ Text {font: Font { size: 20 } content: "First row\nSecond row" } ]
}The resulting screen only shows "Second row", the first line is moved out of the screen above. I need to set y to 20 to show the first line.
Is that normal?Right, Text nodes have an textOrigin, which is default set to the base line. That means that y=0 is just below the letters.
But the behavior is unexpected when simply adding a Text node and nothing is visible. -
The text which is in text node is not displaying in output in smartforms
Hi,
In smartforms i created a text node and entered some text like following.
Target Quantity 60000001 60000002
Scheduled Quantity 60000003 60000004
So far delivered Quantity 60000005 60000006
Last delivered Quantity 60000007 60000008
Delivery Schedule Details
the text which i entered as above in the text node is not displaying.It is in main area.Hi
if u are using table or template inside the main window
then just mention the position of the text element
goto text element - output options- output structure tab----give line and column no.
Thanks
krushna -
Account dimension hierarchy text nodes ACCTYPE property
Hello,
We have master data being populated into BPC from BW. So for the Account dimension in BPC, we use the 0GL_ACCOUNT infoobject in BW. This infoobject also has all the Financial statement version hierarchies which are being loaded to BPC. The question that I have is, how should the hierarchy text node values for ACCTYPE property be populated if I have to automate this load on a daily basis.
For the actual GL accounts, we have the account number ranges defined. Like 1* series accounts are Assets etc..So we can easily define a rule for populating the ACCTYPE property values. But not sure if there is any easy logic for populating the hierarchy text nodes as we dont have any pattern in them. Would we need to maintain it manually always?
Thanks
GauravHello Richard,
If there is really no logic behind them there is off course no way of automating this. Then I guess you will have to maintain each node separately.
Some customers are also willing to change their text node structure. For example I had one when where the rules for the 0HIER_NODE records were as follows:
* EXP -> Starts with 32*, 311*, 312*, 321*, 3111*, 3112*,
* 3142*, 31111*, 31112*, 311111*
* INC -> Starts with TOT, 3000000000, 3100000000, 313*,
* 322*, 3113*, 3141*, 31113*, 311112*
* AST -> Starts with 1*
* LEQ -> Starts with 2*
Kind regards,
Christophe -
How to import hierarchy text node from BW infoobject
I tried to import hierarchy from BW InfoObject through process chain /CPMB/IMPORT_IOBJ_HIER.
But BPC complains the hierarchy text node haven't been dimension member.
As result, I have to export the hierarchy text node to a flat file and import again which is not convenient.
Does anyone have some best practice for this?
Thank you.Hi,
You can follow the steps mentioned in the below How-to-Guide of sdn. This explains the steps to be implemeted to inport hierarchies.
http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/c02d0b47-3e54-2d10-0eb7-d722b633b72e
Hope this helps.
Rgds,
Poonam -
XMLSearch / case in-sensitive search in a text node value with XPATH
Hi everyone,
I was aggregating some XML files and queries for a search
engine. It is pretty easy with coldfusion XML functions BUT ....
I was looking around XMLSearch to do a simple text search
into nodes and I am stuck with it.
with something like that :
selectedElements = XmlSearch(myxmldoc,
'(/directory/user[contains(.,"#form.firstName#")])');
Without loop all the XML elements, I cannot put firstName
text nodes to lower-case, do a simple search into the directory and
get user entries.
Is it possible to do with XPATH something like that :
selectedElements = XmlSearch(myxmldoc,
'(/directory/user[contains(lower-case(.),lower-case("#form.firstName#"))])');
Thanks for your help.When Do you think coldfusion will implement Xpath functions
as
http://www.w3schools.com/xpath/xpath_functions.asp
???? -
How to include std text(Created in So10) in text node?
Hello,
How to include the Standard Text( created in So10 ) into Text Node.
I had typed the Standard text name in the TEXT NAME : ZXXX
Text Object : TEXT
TEXT ID : ST
LAnguage : &CONTROL_PARAMETERS-LANGU&
But, I am unable to look at that particular text in the smart form. I am receiving an error message : "UNable to load the data into front end. ....etc"
It is taking me away to the initial screen.
PLz help!
ANy suggestion will be appreciated.
REgards,
KittuI need to include the Standard text created in so10 into a text node in the Smart form.
In samrt form, I had created a Text Node.
In General attributes from the Drop Down menu
--> I had selected INClude Text
--> It has asked me TExt name : ZXXX (Name of the STD text create din so10)
Text Obje : TExt
Text ID : ST
Language : &CONtrol_Parameters-LANGU&
It is even activated without any errors. But, it does not display the Text written in the Standard Text. Is there any way that I can include the Standard text into the Text node.......
ANy suggestions will be appreciated...
REgards,
Kittu -
hi
apologies for the simple question
ive been searching endlessly for how to add text to a text node
so far I have
text body = doc.createTextNode("mynodename");
previous_element.appendChild(body);
but what mthod do i use to put in the string beween ie
<mynodename>how do i put a string in here</mynodename>
thankselem = doc.createElement("mynodename");
elem.appendChild(doc.createTextNode("how do i put a string in here"));
doc.appendChild(elem); -
XML parser fails to convert html encoded text nodes
Under the strain of large documents this defect rears its ugly head more often. While parsing a text node containing html encoded chars i.e. < > &; etc...
The parser will seemingly forget to change the chars at random, 99.9% of the time everything is ok and the proper conversions take place:
< -> <
> -> >
&; -> &
Once an error occurs it is reproducible until the text node is changed ( values and/or order ) then it is a crapshoot again.
These tests were done using the default UTF-8 encoding, here is the exception thrown by the parser along with a portion of the text node before and after the first parsing.
Let me be clear, the parser actually succeeds the first time but the transformation of the HTML encoded pieces possibly fails. It is on the parsing of the text node value as its own document that the parser fails.
Error 0 : Error parsing XML string! Line :: 1, Column :: 65674
Error 1 : End tag does not match start tag 'Project'.
End tag does not match start tag 'Project'.
at oracle/xml/parser/v2/XMLError.flushErrors (XMLError.java:233)
at oracle/xml/parser/v2/NonValidatingParser.parseDocument (NonValidatingParser.java:248)
at oracle/xml/parser/v2/XMLParser.parse (XMLParser.java:117)
at pacificedge/xml/XMLUtilities.loadParserFromString (XMLUtilities.java:104)
Preprocessing ::
<Project stuff0="0" stuff1="0" stuff2="0" stuff3="1" stuff4="100167" stuff5="100213">
<StuffA>100213</StuffA>
<Name>I am a Name</Name>
<StartDate>1998-08-10</StartDate>
<FinishDate>2000-06-30</FinishDate>
<Path>Folder1\Folder2</Path>
</Project>
Post processing:
<Project stuff0="0" stuff1="0" stuff2="0" stuff3="1" stuff4="100167" stuff5="100213">
<StuffA>100213</StuffA>
<Name>I am a Name</Name>
<StartDate>1998-08-10</StartDate> <-- Error is raised here when the value of the text node is used as an xml document
<FinishDate>2000-06-30</FinishDate>
<Path>Folder1\Folder2</Path>
</Project>
Please investigate this. It is a chronic problem for us and possibly many others.
nullSorry for the encoding issues in the message before here are the pertinent pieces hope this shows up correctly.
&;lt; -> &;#60;
&;gt; -> >
&;amp; -> &;#38;
Preprocessing ::
&;lt;Project stuff0="0" stuff1="0" stuff2="0" stuff3="1" stuff4="100167" stuff5="100213"&;gt;
&;lt;StuffA&;gt;100213&;lt;/StuffA&;gt;
&;lt;Name&;gt;I am a Name&;lt;/Name&;gt;
&;lt;StartDate&;gt;1998-08-10&;lt;/StartDate&;gt;
&;lt;FinishDate&;gt;2000-06-30&;lt;/FinishDate&;gt;
&;lt;Path&;gt;Folder1\Folder2&;lt;/Path&;gt;
&;lt;/Project&;gt;
Post processing:
<Project stuff0="0" stuff1="0" stuff2="0" stuff3="1" stuff4="100167" stuff5="100213">
<StuffA>100213</StuffA>
<Name>I am a Name</Name>
&;lt;StartDate>1998-08-10</StartDate> <-- Error is raised here when the value of the text node is used as an xml document
<FinishDate>2000-06-30</FinishDate>
<Path>Folder1\Folder2</Path>
</Project>
null
Maybe you are looking for
-
my icloud verified email is an old email address i no longer have access too - as it was register to an old employer. i have a new Apple ID (email address) - but when trying to register my icloud to my new email address it says that i have to verify
-
Macbook Pro & Apple TV in Ad-Hoc mode
I have a 802.11b router and am connecting to the network with my laptop and apple tv which I just bought today. The syncing takes forever. Is there any way I can make an ad-hoc network with my laptop and my apple TV so I can get a faster sync? This w
-
Random() with Objective C
I need an absolute number generated from 1 to 4. my random number picked 1-4 in C# picknumber = random.Next(1,5); documentation on random() for Objective C > DOES NOT TELL YOU HOW TO USE IT it just lectures you on what it is, but not how its used. It
-
How to create & Assign unique Qualification level and Groups(Each trans.)
Hi, While working on CRM_LEAD i have observed that i cannot create unique Qualification level or Groups/origins for each transactions, if i add one more Qualification level or Groups/origins in existing table it is reflecting in all corroseponding Le
-
My App Store does not work when trying to update applications
My Apo store does not work when I try to update applications that need to be updated