File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to get attribute values from child nodes in xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get attribute values from child nodes in xml " Watch "How to get attribute values from child nodes in xml " New topic
Author

How to get attribute values from child nodes in xml

kulbhushan patil
Greenhorn

Joined: Aug 10, 2010
Posts: 6
<?xml version="1.0" encoding="UTF-8"?>
<Export version="1.0" type="CTM-MAPPING">

<MetaData>
<MetaDataValue tagname="LeftConnection" id="1" name="My_First_Oracle_Connection"/>
<MetaDataValue tagname="RightConnection" id="2" name="My_Second_Oracle_Connection"/>
</MetaData>

<table >
<Column name="SRC_CONNECTION_ID" replace="CONNECTIONMAP" type="NUMERIC">1</Column>
<Column name="DEST_CONNECTION_ID" replace="CONNECTIONMAP" type="NUMERIC">2</Column>
<Column name="CREATED_BY" replace="DESTINATIONUSER" type="STRING">ADMIN</Column>
<Column name="CREATED_ON" type="DATE">null</Column>
<Column name="MODIFIED_BY" replace="DESTINATIONUSER" type="STRING">null</Column>
<Column name="MODIFIED_ON" type="DATE">null</Column>
<Column name="MAPPING_DATA" type="CLOB"><?xml version="1.0" encoding="UTF-8"?>
<base-mappings><predicates/><scripts/></base-mappings></Column>
<Column name="MAPPING_READ_DATA" type="CLOB"><?xml version="1.0" encoding="UTF-8"?>
<read-mappings><predicates/><scripts/></read-mappings></Column>
<Column name="MAPPING_WRITE_DATA" type="CLOB"><?xml version="1.0" encoding="UTF-8"?>
<write-mappings><predicates/><scripts/></write-mappings><design-mappings-xml><?xml version="1.0" encoding="UTF-8"?>
<design-mappings><predicates/><logical-units><logicalunit creation-date="10/03/2012 15:11:23" creator="ADMIN" mapping-name="design_test_1" name="design_test_1"><object id="Enterprise_Employee"mapping-name="design_test_1" name="Enterprise_Employee" x="-150"




The above is my sample xml file and i have to extract mapping name value from it but i am getting only column node from both sax and dom parser please help me how to extract it
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

kulbhushan patil wrote:i have to extract mapping name value from it but i am getting only column node from both sax and dom parser


Then there's a bug in your code and you need to fix it.

please help me how to extract it


Provide an SSCCE(←click) that has just enough code to show the problem, and nothing else, and indicate clearly observed and desired behavior.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Pretty sure you can't just embed an XML doc inside another one though without at least using CDATA or something. Having this in the middle of your doc is likely to be problematic: <?xml version="1.0" encoding="UTF-8"?>
kulbhushan patil
Greenhorn

Joined: Aug 10, 2010
Posts: 6
Jeff i have attached sample xml file which i have to parse and i have have to extract from it attribute named "mapping-name" from "logicalunit" node
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

kulbhushan patil wrote:Jeff i have attached sample xml file which i have to parse and i have have to extract from it attribute named "mapping-name" from "logicalunit" node


1. I see no attachment. Do you mean the XML in the body of your first post?

2. I'm not convinced you're starting with well-formed XML. If it's not well-formed, there's no point in trying to parse it.

3. I still don't see the SSCCE I asked for.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18713
    
    8

No, what you posted is not well-formed XML. So I agree with Jeff, that's most likely your problem.
 
jQuery in Action, 2nd edition
 
subject: How to get attribute values from child nodes in xml