How to read xml file that has changing element names?

Idon't know much about xml, nor reading it with java, but I have this problem with reading xml file. The file something like this:
<configuration>
   <DEV001>
      <serial>001</serial>
      <id>number 1</id>
   </DEV001>
   <DEV002>
      <serial>002</serial>
      <id>number 2</id>
   </DEV002>
</configuration>I have imported the org.w3c.dom.* api, that I use for parsing. I don't know is this a generic or a parser specific issue, but how can I get all the nodes starting with "DEV" into a NodeList?
If you know a solution for this with another parser, please share it. I have no reason to use that specific parser, I just found a sample using that.
kari-matti

Well, NodeList is an interface, so you cannot construct one and put the "good" elements into it. But, you might be able to cast the NodeList with all of the children of the root into an IIOMetadaNode (which is the class that implements the NodeList interface. That class has a removeChild() method that might be able to remove the text nodes and any that don't start with DEV.
But, if you remove nodes, and still want to do things with the full DOM Document, be very careful and run tests. It may remove those nodes from the full Document.
If, on the other hand, the printingData( Nodelist nl) method could be modified so it takes an ArrayList or some other collection, it is very simple.
Just create an ArrayList, and when you find an element starting with DEV, add it to the ArrayList. When you are done, process that list and you are finished.
Dave Patterson

Similar Messages

  • How to read XML file and write into another XML file

    Hi all, I am new to JAVAXML.
    My problem is I have to read one XML file and take some Nodes from that and write these nodes into another XML file...
    I solved, how to read XML file
    But I don't know how to Write nodes into another XML.
    Can anyone help in this???
    Thanks in advance..

    This was answered a bit ago. There was a thread called "XML Mergine" that started on Sept 14th. It has a lot of information about what it takes to copy nodes from one XML Document object into another.
    Dave Patterson

  • How to read .xml file from embedded .swf(flash output) in captivate

    I have been trying to read .xml file from the .swf (Flash output) that is embedded within the captivate file but no luck yet . Please if anyone got any clue on how get this thing done using Action script 3.0 then let me know. I am using Adobe Captivate 5.5 at present and Flash CS 5.5.
    I am well aware about how to read .xml file through action script 3.0 in flash but when insert the same flash in captivate and publish nothing comes in captivate output. I would higly appreciate if anyone could help me out with that.
    Here is is graphical demonstration of my query :
    Message was edited by: captainmkv

    Hi Captainmkv,
    Does the information in this post cover what you're trying to do: http://forums.adobe.com/message/5081928#5081928
    Tristan,

  • How to get PDF file that has been transformed into docx into my filing system so I can work on it???

    How can I get the PDF file that was transformed into a docx file into my filing system to be able to work on it and translate it as the customer requested?

    THanks for your reply.
    Well what happens is I bought the program. It gives you a button to click,
    you log in and then a box opens up asking you to select the file, I go into
    my filing system (in Windows explorer) select the file, and the program
    converts it into docx, my choice.  I can read it there and when I try to
    copy and paste it into my file where the PDF version is saved, it behaves
    like an "image", and I can't save it.... or it saves likes something you
    save on the internet, so you have to go into internet every time you want
    to see it.    I have also pressed any amount of buttons to see if it will
    give me the option to save it any other way, and have found nothing.  What
    I would need is a file in docx.format that I can edit.  People send me
    things in PDF and sometimes I can just copy it off the PDF file and save it
    in WOrd, then I can translate it for them. But sometimes the PDF file
    doesnt allow me to copy the text.  If it is in image form, I cannot work on
    it.  It means printing it, so I can copy type it into Word... and for that
    I certainly wouldnt need to buy a program.  Its just double the work and
    ends up that the job takes twice as long.!
    Sorry  if I am a bit dumb with informatics.  But I simply could not find
    any way whatever to  copy the PDF file that was transformed into Word, in a
    format that would enable me to edit it.
    Kindest regards,
    Margery
    2013/12/2 Test Screen Name <[email protected]>
        Re: How to get PDF file that has been transformed into docx into my
    filing system so I can work on it???
    created by Test Screen Name<http://forums.adobe.com/people/TestScreenName>in *Adobe
    ExportPDF* - View the full discussion<http://forums.adobe.com/message/5890871#5890871

  • How to read xml file as shown below.

    Hello,
    I am using flash builder 4 and currently working on implementing AIR application.
    I need to read xml file data.
    Normal xml files are easy to read and i am much more aware of it.
    But can any one have idea how to read XML file which is given below.
    <node>
    <key>ID</key>
    <integer>1</integer>
    <key>Name</key>
    <string>Dhwani</string>
    <key>Postno</key>
    <integer>20</integer>
    <key>deskname</key>
    <string>flex</string>
    <key>empid</key>
    <integer>25</integer>
    <key>projectname</key>
    <string>abc</string>
    </node>
    Here i have xml file in form of key value pair. <key> node shows name of the key and after that <integer> or <string> node are the value for that specific key.
    if i select node.key then it shows me all the keys. and from that i cant make out what is the value for key ID.
    Is there any way to take first node and then second. i mean first i ll take value of key and store it into some arraycollection. and then value will be stored.
    Any help is appreciated.. Looking for positive reply.
    Thanks
    Dhwani

    There are different methods to access XML data which have pro's and cons. Let us know more about what you want to do and we can help you.

  • How to read XML file kept on NON-SAP server using the Http URL ?

    Dear Experts,
    I am working on CRM2007 web UI. I need to read a XML file placed on a shared server location by a third party program. Then process that XML file into CRM and create a quotation using the data extracted from the file.
    All i have with me is the http URL that points to the location of the file.
    I am supposed to read the file , create quotation and at later point of time i would be asked to update the quotation and then generated new XML representing updated quotation and replace the XML file on shared server location with this new updated XML file.
    I know how to extract data from XML file into ABAP but i have no clue as to how to access the file on some other server using the http url i have and how to read it ?
    I searched on the forum and i found the codes for reading XML file that is located either on client machine OR on the Application server wheareas my file is on some other than sap application server.
    Please help me as its an urgent issue .
    Points will be rewarded for sure.
    Please help.
    Thanks in advance,
    Suchita.
    p.s. : the http url to the file location is like -->
    http://SomeServerDomain/SomeDirectory/file.xml

    hi,
    interesting task.
    to request the file by a http call you need to create an if_http_client object.
    More info is [here|http://help.sap.com/saphelp_nwmobile71/helpdata/en/e5/4d350bc11411d4ad310000e83539c3/frameset.htm]
    to parse the file you either have to work with the ixml packages ([info|http://help.sap.com/saphelp_nwmobile71/helpdata/en/47/b5413acdb62f70e10000000a114084/content.htm]) or you use an XSLT transformation ([info|http://help.sap.com/saphelp_nwmobile71/helpdata/en/a8/824c3c66177414e10000000a114084/content.htm]).
    uploading the final file isn't so easy. if you only have http, you should write a server script to allow uploading of the new file and copying it into the place of the old file. but you definitely need the script.
    now it's your take. depending on how experienced you are in ABAP and networking this might turn out to be easy or pretty complicated.
    have fun,
    anton

  • How to read XML file and update the data in MS CRM 2011?

    Hi Folks,
    Can anyone please help me finding some references to read XML files and push the data to MS CRM 2011 preferably by using a console application.
    Please let me know if any ways of handling it in simple ways.
    Thanks,
    Sri

    HI,
    How to read XML file:
    https://social.msdn.microsoft.com/Forums/en-US/5dd7261b-86c4-4ca8-ba87-95196ef3ba50/need-to-display-xml-file-in-textboxes-edit-the-data-and-save-the-new-xml-file?forum=csharpgeneral
    How to work with CRM:
    ClientCredentials credentials = new ClientCredentials();
    credentials.Windows.ClientCredential = new System.Net.NetworkCredential("USER", "Password", "Domain");
    Uri uri = new Uri("http://server/Organization/XRMServices/2011/Organization.svc");
    OrganizationServiceProxy proxy = new OrganizationServiceProxy(uri, null, credentials, null);
    proxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
    IOrganizationService service = (IOrganizationService)proxy;
    //using "service" you can create, update and retrieve entities.
    More information here about service functions:
    https://msdn.microsoft.com/en-us/library/gg328198.aspx

  • How to read xml file and place it into an internal table...

    hello all,
    can any one help me in - how to read xml data file (placed in application server) and placing the same into an internal table (remove the xml tags or say fetching the xml data without xml tags).

    Hi Murashali,
    use this.
    TYPES: BEGIN OF day,
    name TYPE string,
    work(1) TYPE c,
    END OF day.
    DATA: BEGIN OF week,
    day1 TYPE day,
    day2 TYPE day,
    day3 TYPE day,
    day4 TYPE day,
    day5 TYPE day,
    day6 TYPE day,
    day7 TYPE day,
    END OF week.
    DATA xml_string TYPE string.
    DATA result LIKE week.
    week-day1-name = 'Monday'. week-day1-work = 'X'.
    week-day2-name = 'Tuesday'. week-day2-work = 'X'.
    week-day3-name = 'Wednesday'. week-day3-work = 'X'.
    week-day4-name = 'Thursday'. week-day4-work = 'X'.
    week-day5-name = 'Friday'. week-day5-work = 'X'.
    week-day6-name = 'Saturday'. week-day6-work = ' '.
    week-day7-name = 'Sunday'. week-day7-work = ' '.
    CALL TRANSFORMATION ...
    SOURCE root = week
    RESULT XML xml_string.
    CALL TRANSFORMATION ...
    SOURCE XML xml_string
    RESULT root = result.
    Regards,
    Vijay

  • How to read .dat files that are hidden?

    Is it possible to read .dat files that are set to hidden? 'cause what i did was i created a .dat file and set its attributes to hidden and my Read file code cannot read hidden files.
    here's my Read file code:
    Scanner read=new Scanner(FileReader("C:\password.dat"));
    and another thing, how do you Write a .dat file that is hidden too? 'cause my password.dat file needs to be updated.
    here's my Write file code:
    PrintWriter write=new PrintWriter("C:\password.dat");
    thank for the help.

    There should not be any problems opening up hidden files. Your problem is probably elsewhere (for example, you didn't escape the backslash, so what you posted is not your code).

  • How to Read XML files in OC4J???

    I wrote a Web Application with JBuilder, and deployed it in OC4J.
    In the Web App, there were a class and a Jsp, following:
    in the class:(load the .xml file and get the element's attribute value)import org.jdom.Element;
    import org.jdom.Document;
    import org.jdom.input.SAXBuilder;
    public Document loadXMLDoc(String AFileName) throws Exception
    SAXBuilder lSAXBuilder = new SAXBuilder(false);
    Document lDoc = lSAXBuilder.build(AFileName);
    return lDoc;
    public void testGetXMLValue(String AFileName)
    throws Exception
    Document lDoc = null;
    Element lElement = null;
    Element lElement1 = null;
    try
    lDoc = loadXMLDoc(AFileName);
    lElement = lDoc.getRootElement().getChild("client-setup.xml");
    lElement1 = lElement.getChild("connection-params");
    catch (Exception e)
    e.printStackTrace();
    throw new Exception(lErrorStr);
    in the JSP:(invoking the class's method)<%
    testJspBeanId.testGetXMLValue("client-setup.xml");
    %>
    When compiling the Web App, I had contained the "jdom.jar" and "xerces.jar" packages in .ear file,
    After deploying the .ear in OC4J, the two packages in the "/applications/Web App/Web App/WEB-INF/lib/"
    but when I run the Web App to , Error took place:
    org.jdom.JDOMException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found:in deed:
    "Document lDoc = lSAXBuilder.build(AFileName);" bring on the error,
    but I can't resolve it and I am needing your help!!!
    Thank you.

    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.io.SAXReader;
    import java.io.File;
    import java.text.AttributedCharacterIterator.Attribute;
    import java.util.Iterator;
    import java.util.StringTokenizer;
    public class XmlParser
    private String Result="";
    private String Final="";
    private String Delim="";
    public void bar1(Document document) throws DocumentException
    org.dom4j.Element root = document.getRootElement();
    // System.out.println(root.getName());
    bar2(root);
    System.out.println(this.Result);
    process();
    public void bar2(org.dom4j.Element e)
    for(Iterator i = e.elementIterator();i.hasNext();)
    org.dom4j.Element Element = (org.dom4j.Element) i.next();
    Result += Element.getName()+"\t"+Element.getText()+"\n";
    bar2(Element);
    public void process()
    StringTokenizer Tokenizer = new StringTokenizer(this.Result,"\n");
    String element;
    while(Tokenizer.hasMoreTokens())
    element = Tokenizer.nextToken();
    StringTokenizer Tokenizer2 = new StringTokenizer(element,"\t");
    // Do what ever String Process here Example
    this.Final += element.getName();
    this.Final += this.Delim;
    System.out.println(this.Final);
    public static void main(String s[])throws Exception
    Document document = null;
    SAXReader reader = new SAXReader();
    File f1= new File("D:/Rajesh/EDI to XML/EDI.xml");
    document = reader.read(f1);
    Demo obj = new Demo();
    obj.bar1(document);
    i think this will hep full.......

  • How to read xml file present in the UCMS from  webcenter portal application

    Hi,
    I'm new to webcenter portal and would like to know how to read an xml file which is present in UCMS 11g(contributors folder) from webcenter portal application.
    Thanks in advance

    I guess I had mentioned that I want to read it via my webcenter portal app rather than login to ucms and searching it via url.
    I want text labels and button names being stored in the xml file which I'm going to keep in the UCMS.
    After reading that from the xml will be placed at appropriate locations like the button values and label feilds, so that we dont need to deploy entire app for this kind of simple changes.
    Now can anyone provide some help with the api's related to this?

  • How to read a file which has header and without header

    Hi,
    I have a file to file scenario wherein there are txt files in the source system, some of which has header and some without header.
    How does the sender adapter dynamically identify a file with header and without header.
    I knew that File content Conversion in the sender adapter with "Recordsets per message = 1" can read the header.  But how to handle dynamically.
    Thanks in advance for suggestions and advice.
    Regards.
    Praveen

    Hi,
    Let me give a more clear picture:-
    One of my file which has header and the corresponding values is listed hereunder:
    PERNR;KID;PNALT;NACHN;NAME2;VORNA;TITEL;TITL2 and so on.....
    ;1200;1200;Angus;; and so on.........
    Other file which has no header but only values in it:-
    1200;1200;;Werner;Angus and so on.......
    The structure remains same for all the files.  The only difference is that some of the file has header in it and some without header.  The Message Type is mentioned hereunder:-
    DT_LegacyEmployee (Category - Complex Type)
         Employees (Category - Element, Occurence - 1)
              Employee (Categroy - Element, Type - DT_LegacyEmployee_Row, Occurence - 0...unbounded)
                   PERNR
                   KID
                   PNALT
                   NACHN
                   NAME2 and so on......     
    I read the file in record row.  The file conversion parameters in the file sender adapter are mentioned hereunder:-
    Document Name - MT_LegacyEmployee
    Document Namespace - http://abc.com/xi
    Recordset Name - Employees
    Rescordset Structure - Employee,*
    Recordsets per Message - 1
    Key Field Type - String (Case Sensitive)
    Employee.fieldSeparator - ;
    Employee.endSeparator - 'nl'
    Employee.fieldNames - PERNR,KID,PNALT,NACHN,NAME2,VORNA,TITEL,TITL2 and so on........
    How do we dynamically identify whether the file has header or not.  Even if the file has header or without header, the file needs to be picked and transferred to the target system.  Kindly clarify.
    Regards.
    Praveen

  • How to read xml file

    I want to create a component to read a XML file in Flex 2
    using Actionscript. I am able to do this using URLRequest and
    URLLoader but what happens is the component that calls my reader
    component keeps running through the code and the Complete event
    never gets called.
    So my question is how can I read a XML file through AS and
    return a value in that XML file all in a synchronized manner?
    Thanks

    All data access in Flex is asynchronous.
    There is NO WAY to stop or pause code execution in the Flash
    Player.
    You will need to use events to complete the processing after
    the call returns. This is a tough paradigm if you are new to it,
    but there is no other way.
    Resistance is futile.
    Also, in a related vein, Alert and other "modal" pop-ups are
    not truly modal. They do not stop code execution, and you must use
    events to continue processing.
    Tracy

  • How to Read Xml File and view into Data Grid View?

    hi all
    my Data into Xml file are:
    <Voucher>
    <Header>
    <txtHeaderId>259803</txtHeaderId>
    <txtDate>2015/02/01</txtDate>
    <txtDocNo>20</txtDocNo>
    <txtMemo>This is a Test .</txtMemo>
    </Header>
    <Item>
    <txtItemId>8562803</txtItemId>
    <txtHeaderRef>259803</txtHeaderRef>
    <txtDesc>This is Number 1</txtDesc>
    <txtDebit>350000</txtDebit>
    <txtCredit>0</txtCredit>
    <txtItemId>8562804</txtItemId>
    <txtHeaderRef>259803</txtHeaderRef>
    <txtDesc>This is Number 2</txtDesc>
    <txtDebit>0</txtDebit>
    <txtCredit>350000</txtCredit>
    </Item>
    </Voucher>
    now i have two DataGridViews 
    i want that data from xml file show into the DataGridViews by this codes:
    Private Sub btnReadXmlFile_Click(sender As Object, e As EventArgs) Handles btnReadXmlFile.Click
    Dim Document As XmlReader = New XmlTextReader(txtPath.Text)
    Dim ds As New DataSet
    ds.ReadXml(Document)
    DataGridView1.DataSource = ds.Tables(0)
    End Sub
    but i see this result:
    why i do not see any result into DataGridView2(Item)
    how to solve it ?
    please help me .
    thanks all
    Name of Allah, Most Gracious, Most Merciful and He created the human

    now how to correct it?
    Name of Allah, Most Gracious, Most Merciful and He created the human
    Please be explicit - I'm the only other one in this thread so I assume it's to me, but usually I just ignore the posts when the user isn't specific.
    I don't know what there is to correct. Create a NEW dataset in code, add the two tables, and use the methods that I suggested.
    I'm not a database guy so I can't get real specific. I create my own stuff in classes and use that but, if you're using SQL then there are lots of pro's here that can help you with specifics. I'm sure they'll need to know a lot more about your data, the
    connection, and all that, but the concept should be fairly simple to implement.
    Still lost in code, just at a little higher level.

  • How to read XML files from java

    i need a sugession that how to read a xml file using java code
    and i need to parse using some parsers and display attributes and entity seperately
    as a string.......

    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.io.SAXReader;
    import java.io.File;
    import java.text.AttributedCharacterIterator.Attribute;
    import java.util.Iterator;
    import java.util.StringTokenizer;
    public class XmlParser
    private String Result="";
    private String Final="";
    private String Delim="";
    public void bar1(Document document) throws DocumentException
    org.dom4j.Element root = document.getRootElement();
    // System.out.println(root.getName());
    bar2(root);
    System.out.println(this.Result);
    process();
    public void bar2(org.dom4j.Element e)
    for(Iterator i = e.elementIterator();i.hasNext();)
    org.dom4j.Element Element = (org.dom4j.Element) i.next();
    Result += Element.getName()+"\t"+Element.getText()+"\n";
    bar2(Element);
    public void process()
    StringTokenizer Tokenizer = new StringTokenizer(this.Result,"\n");
    String element;
    while(Tokenizer.hasMoreTokens())
    element = Tokenizer.nextToken();
    StringTokenizer Tokenizer2 = new StringTokenizer(element,"\t");
    // Do what ever String Process here Example
    this.Final += element.getName();
    this.Final += this.Delim;
    System.out.println(this.Final);
    public static void main(String s[])throws Exception
    Document document = null;
    SAXReader reader = new SAXReader();
    File f1= new File("D:/Rajesh/EDI to XML/EDI.xml");
    document = reader.read(f1);
    Demo obj = new Demo();
    obj.bar1(document);
    i think this will hep full.......

Maybe you are looking for

  • Not receiving bt emails on blackberry

    I hope I'm posting in the right place and desperately need help.  I have, probably, a first gen Blackberry.  My wife's is newer but certainly not the latest. No problems with email change on desktop but not receiving on Blackberry.  This is very inco

  • How can I get the activate icloud email resent to me?

    I am trying to activate iclound for my iphone and the phone is telling me that I need to check my email to verify the account.  When I check the email the verification email is not present.

  • N82 Problem of synchronization with PC Suite

    I just bought a N82 last week. And of course I want to synchronize my outlook address book into the new cell phone. How ever the poblem happened when I using PC Suite. The following is the details. Enviroment: Nokia PC Suite version 7.0.7.0 PC OS - W

  • 3GS Lost 3g Signal after update to 4.1

    I have this 3GS, i used a loot of time whit 4.0 software. after the upgrade to 4.1 the iphone dont get 3g signal, i need to put it off the 3g to get signal. and use the phone, if i put on the 3g on again i get just "No service". Somebody can help me?

  • R12 Purchasing & Oracle Pricing Modifiers

    Hi, I'm looking for setup document / case studies, where Oracle Pricing modifiers are used for PO pricing. Most of the doc's give details on sales side pricing, but not on PO side. Thanks in advance. -Bhaskar