Help Parsing XML Mesage using PeopleCode

Hi all,
I'm new to web services and XML but was able to consume a WSDL and call the web service successfully.
I'm now trying to parse the XML message I’m getting as a response and to extract values i need and having issues Parsing the response. Below is what I have done and the code from my Test AE. Basically I’m trying to navigate to the "Results" element in the response and then use GetChildNode to get child nodes and then use FindNode to find elements and their values.
Here is the WSLD I consumed to create the web service in PS. I only need WSDL operation doSearch_3_15
[https://www.epls.gov/epls/services/EPLSSearchWebService?wsdl ]
My PC below calls the web service and passes last name “ZERMENO” as a search parameter and this should return 3 results back.
I’m grabbing the reply back and parse it to extract the values I need.
+&inXMLDoc = CreateXmlDoc("");+
+&ret = &inXMLDoc.ParseXmlString(&reply.GenXMLString());+
The issue I’m having is being able to get “inside” the results node (there are 3 of them) and loop through the child nodes and get my values.
Code from Test AE:
Local string &payload, &responseStr, &last;
Local Message &msg, &reply;
Local XmlDoc &xml, &inXMLDoc;
Local array of XmlNode &GetElements, &RecordList, &field1List, &aResultsNode;
Local XmlNode &RecordNode, &ClassificationNode;
Local File &MYFILE;
+&FilePath = "/psoft/fin9/fpsdv1/prod/ap/files/";+
+&FileName = "uhc_report.xml";+
+&MYFILE = GetFile(&FilePath | &FileName, "W", %FilePath_Absolute);+
+&payload = "<?xml version='1.0'?> <doSearch xmlns='https://www.epls.gov/epls/services/EPLSSearchWebService'>";+
+&first = "";+
+&last = "ZERMENO";+
+&payload = &payload | "<query><first>" | &first | "</first><last>" | &last | "</last></query> </doSearch>";+
+&xml = CreateXmlDoc(&payload);+
+&msg = CreateMessage(Operation.DOSEARCH_3_15, %IntBroker_Request);+
+&msg.SetXmlDoc(&xml);+
+&reply = %IntBroker.SyncRequest(&msg);+
If All(&reply) Then
If &MYFILE.IsOpen Then
+&MYFILE.WriteString(&reply.GenXMLString());+
Else
MessageBox(0, "", 0, 0, "Can't Open File.");
End-If;
+&inXMLDoc = CreateXmlDoc("");+
+&ret = &inXMLDoc.ParseXmlString(&reply.GenXMLString());+
If &ret Then
+&field1List = &inXMLDoc.GetElementsByTagName("results");+
If &field1List.Len = 0 Then
MessageBox(0, "", 0, 0, "GetElementsByTagName Node not found");
Error ("GetElementsByTagName Node not found");
+/* do error processing */+
Else
For &j = 1 To &field1List.Len
If &j > 1 Then
+MessageBox(0, "", 0, 0, &field1List [&j].NodeName | " = " | &field1List [&j].NodeValue);+
+&RecordNode = &inXMLDoc.DocumentElement.GetChildNode(&j);+
If &RecordNode.IsNull Then
MessageBox(0, "", 0, 0, "GetChildNode not found");
Else
+&ClassificationNode = &RecordNode.FindNode("classification");+
If &ClassificationNode.IsNull Then
MessageBox(0, "", 0, 0, "FindNode not found");
Else
+&SDN_TYPE = Substring(&ClassificationNode.NodeValue, 1, 50);+
MessageBox(0, "", 0, 0, "&SDN_TYPE = " | &SDN_TYPE);
End-If;
End-If;
End-If;
End-For;
End-If;
MessageBox(0, "", 0, 0, &inXMLDoc.DocumentElement.NodeName);
Else
+/* do error processing */+
MessageBox(0, "", 0, 0, "Error. ParseXml");
End-If;
Else
MessageBox(0, "", 0, 0, "Error. No reply");
End-If;
see link below for the XML reply web service message with some Notes. Also link for the response as an XML doc (had to add .txt to the xml extension to be able to upload it).  I appreciate your help and feedback.
http://compshack.com/files/XML-Message.png
http://compshack.com/files/uhc_report.xml_.txt
And here is the output from my Test AE. I'm able to find 3 count of results, which i expected since I have 3 records coming back from the web service, but for what ever reason, GetChildNode is failing.
results = (0,0)
GetChildNode not found (0,0)
results = (0,0)
GetChildNode not found (0,0)
results = (0,0)
GetChildNode not found (0,0)
Edited by: Maher on Mar 12, 2012 10:21 AM
Edited by: Maher on Mar 12, 2012 10:41 AM

Hi,
I just took a closer look at the code and the looping using childnodes and findnode is not correct a bit overkill.
You should really use the one or the other.
I have created two other loops
Loop 1, loop through all elements using Childnodes:
Local string &payload, &responseStr, &last;
Local Message &msg, &reply;
Local XmlDoc &xml, &inXMLDoc;
Local array of XmlNode &GetElements, &RecordList, &field1List, &aResultsNode;
Local XmlNode &RecordNode, &ClassificationNode;
Local File &MYFILE;
&inXMLDoc = CreateXmlDoc("");
&ret = &inXMLDoc.ParseXmlFromURL("c:\temp\test.xml");
If &ret Then
   &field1List = &inXMLDoc.GetElementsByTagName("results");
   If &field1List.Len = 0 Then
      MessageBox(0, "", 0, 0, "GetElementsByTagName Node NOT found");
      Error ("GetElementsByTagName Node NOT found"); /* do error processing */
   Else
      For &j = 1 To &field1List.Len
         If &j > 1 Then
            MessageBox(0, "", 0, 0, &field1List [&j].NodeName | " = " | &field1List [&j].NodeValue);
            &RecordNode = &field1List [&j];
            &RecordChildNode = &RecordNode.GetChildNode(&j);
            If &RecordChildNode.IsNull Then
               MessageBox(0, "", 0, 0, "GetChildNode NOT found");
            Else
               MessageBox(0, "", 0, 0, "&RecordChildNode name:" | &RecordChildNode.NodeName);
               If &RecordChildNode.NodeName = "classification" Then
                  MessageBox(0, "", 0, 0, "NodeName = " | &RecordChildNode.NodeName);
                  &SDN_TYPE = Substring(&RecordChildNode.NodeValue, 1, 50);
                  MessageBox(0, "", 0, 0, "&SDN_TYPE = " | &SDN_TYPE);
               End-If;
            End-If;
         End-If;
      End-For;
   End-If;
   MessageBox(0, "", 0, 0, &inXMLDoc.DocumentElement.NodeName);
Else /* do error processing */
   MessageBox(0, "", 0, 0, "Error. ParseXml");
End-If;results = (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: results = (0,0) (0,0)
&RecordChildNode name:address (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: &RecordChildNode name:address (0,0) (0,0)
results = (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: results = (0,0) (0,0)
&RecordChildNode name:agencyUID (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: &RecordChildNode name:agencyUID (0,0) (0,0)
results = (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: results = (0,0) (0,0)
&RecordChildNode name:classification (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: &RecordChildNode name:classification (0,0) (0,0)
NodeName = classification (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: NodeName = classification (0,0) (0,0)
&SDN_TYPE =
Individual (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: &SDN_TYPE =
Individual (0,0) (0,0)
soapenv:Envelope (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: soapenv:Envelope (0,0) (0,0)
Loop 2, look for classification node, using FindNode:
Local string &payload, &responseStr, &last;
Local Message &msg, &reply;
Local XmlDoc &xml, &inXMLDoc;
Local array of XmlNode &GetElements, &RecordList, &field1List, &aResultsNode;
Local XmlNode &RecordNode, &ClassificationNode;
Local File &MYFILE;
&inXMLDoc = CreateXmlDoc("");
&ret = &inXMLDoc.ParseXmlFromURL("c:\temp\test.xml");
If &ret Then
   &field1List = &inXMLDoc.GetElementsByTagName("results");
   If &field1List.Len = 0 Then
      MessageBox(0, "", 0, 0, "GetElementsByTagName Node NOT found");
      Error ("GetElementsByTagName Node NOT found"); /* do error processing */
   Else
      For &j = 1 To &field1List.Len
         If &j > 1 Then
            &RecordNode = &field1List [&j];
            &ClassificationNode = &RecordNode.FindNode("classification");
            If &ClassificationNode.IsNull Then
               MessageBox(0, "", 0, 0, "FindNode not found");
            Else
               &SDN_TYPE = Substring(&ClassificationNode.NodeValue, 1, 50);
               MessageBox(0, "", 0, 0, "&SDN_TYPE = " | &SDN_TYPE);
            End-If;
         End-If;
      End-For;
   End-If;
   MessageBox(0, "", 0, 0, &inXMLDoc.DocumentElement.NodeName);
Else /* do error processing */
   MessageBox(0, "", 0, 0, "Error. ParseXml");
End-If;&SDN_TYPE =
Individual (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: &SDN_TYPE =
Individual (0,0) (0,0)
&SDN_TYPE =
Individual (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: &SDN_TYPE =
Individual (0,0) (0,0)
&SDN_TYPE =
Individual (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: &SDN_TYPE =
Individual (0,0) (0,0)
soapenv:Envelope (0,0)
Message Set Number: 0
Message Number: 0
Message Reason: soapenv:Envelope (0,0) (0,0)
As you can see, several possible solutions are possible.
Hope this helps.
Hakan

Similar Messages

  • Please help parse XML

    First, the a sample XML to be parsed:
    <item name='HTMLContent_3'><richtext>
    <pardef id='1' leftmargin='1in' rightmargin='100%' tabs='L0.5000in L1in L1.5000in L2in L2.5000in L3in L3.5000in L4in'/>
    <par def='1'><p class="MsoBodyText">N.A.</p></par></richtext></item>This code is exported from a Lotus Domino database and represents a richtext field. I just want to export the text; in this case, that is the "N.A." and keep the line-breaks. Text formatting, bolding, etc. does not matter.
    Some <item> nodes are very long, with multiple <pardef> and <par def='1'> elements. Also, in my text editor greater than and less than symbols around the paragraph tag is listed as "<" and ">" (but I doubt that's a factor in the parsing).
    The <item> element is passed into the code sample below as Element e. I can get down to the <richtext> element with:
    Node child = e.getFirstChild();Then I can get the <pardef> and <par> nodes with:
    NodeList paragraphs = child.getChildNodes();But anything I try to get the text out of those nodes fails with a cast exception, prints out the XML, or doesn't do anything at all. Here is my current attempt:
    public static String getLongCharDataFromRichtext(Element e) {
         String answer = "";
         Node child = e.getFirstChild();     // Should be the <richtext> element.
         NodeList paragraphs = child.getChildNodes();
         for (int i=0; i<paragraphs.getLength(); i++) {
    //          String txt = paragraphs.item(i).toString();
    //          System.out.println(txt);
    //          answer += txt;
              Node paragraph = (Node)paragraphs.item(i);
              System.out.println(paragraph.toString());
    //          if (paragraph.getNodeType() == 3) {   // node type 3 is text node.
    //               String txt = paragraph.getNodeValue();
    //               String txt = getCharacterDataFromElement(paragraph);
    //               answer += txt;
         return answer;
    }I've been stumped on this for a while so I really, really appreciate your help!.
    -Jeff

    OK. I get what you're saying (including the hint that maybe this should have gone in the "New to Java" forum <G>). But now I'm having a second problem. The XML parser does not recognize the paragraph tags as an extra node on the tree.
    First, here is my current code:
    public static String getLongCharDataFromElement(Element e) {
         String answer = "";
         Node child = e.getFirstChild();     // Should be the <richtext> element.
         NodeList paragraphs = child.getChildNodes();
         for (int i=0; i<paragraphs.getLength(); i++) {
              Node paragraph = (Node)paragraphs.item(i);
              if (paragraph.getNodeName().equalsIgnoreCase("par")) {
                   Node theText = paragraph.getFirstChild();
                   String val = theText.getNodeValue();
                   System.out.println(val);
    }When I print out val, it prints the entire text of the paragraph tag (including the tag). I can't get a child node and I can't cast it to an Element or do anything.
    The XML parser I'm using is as follows:
    File file = new File("Answers.dxl");
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(file);Why won't the parser recognize the paragraph tags as a new Node?
    Thanks,
    -Jeff

  • Help In XML schema using  oracle 10g

    i want to give seminar in XML schema using oracle 10g. n i m very new in this topic. so help me out which topic i include & any document regarding this

    XML Schema has various aspects.
    1. Creating an XML Schema, which may be done in JDeveloper.
    2. Initializing an XML document from an XML Schema, which may also be done in JDeveloper.
    For creating and initializing an XML Schema please refer
    http://www.regdeveloper.co.uk/2007/10/01/build_xml_schema_jdeveloper/
    3. Validating an XML document with an XML Schema.
    http://www.oracle.com/technology/pub/articles/vohra_xmlschema.html

  • Need Help Parsing JSON String using PLJSON

    Hello,
    I have JSON stored in a database field:
    --Query
    select data1 from table1 where id= 339207152427;
    --Results:
    [{"name":"Home"},{"code":"JPNWC74ZKW9"},{"start date":"01\/02\/2014"},{"person name":"hhh, RamS"}]
    I need to parse the above results into 3 fields in a separate table. For now, i'm just trying to parse the results using PLJSON, but am getting the ORA-20101: JSON Parser exception - no { start found error when running the following pl/sql block:
    declare
    VIN_JSON varchar2(4000);
    jsonObj json;
    listOfValues json_list;
    listElement json_value;
    begin
    select data1 into VIN_JSON from table1 where id= 339207152427;
    jsonObj := new json(VIN_JSON);
    listOfValues := jsonObj.get_values();
    for i in 1..listOfValues.count loop
    listElement := listOfValues.get(i);
    end loop;
    end;
    I believe my syntax is close, but was hoping for some further instruction.
    Thanks in advance!
    John

    I have no idea what you are trying to do or in what version so help, at this point, is not possible.
    Let's start with this:
    I need to parse the above results into 3 fields in a separate tableAnd the parsing rules?
    And what the result should be?
    You apparently want us to guess. Which is something most of us do not like to do. (and don't forget your full version number if you want help).
    PS: This forum has a FAQ: I recommend you read it as you didn't even put your listing into tags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Help parsing XML file

    Hi All,
    I have some troubles trying to load and parse a simple xml file like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <entry>
         <id>1</id>
    </entry>
    <entry>
         <id>2</id>
    </entry>
    With this few lines of code:
                var url:URLRequest = new URLRequest("myXML.xml");
                var xml:XML;
                var rss:URLLoader = new URLLoader();
                rss.load(url);
                rss.addEventListener(Event.COMPLETE, readRss);
                function readRss(e:Event):void{
                    xml = XML(rss.data);               
                    var ns:Namespace=xml.namespace();
                    txt_field.text=xml..ns::entry[0].ns::id;           
    I get this error: A conflict exists with inherited definition spark.components:Application.url in namespace public.
    in: var url:URLRequest = new URLRequest("myXML.xml");
    Please help me ...  thank you in advance.
    Michele

    Hi Michele,
    Try to use different name for your URLRequest object...It seems that there is conflict existing with the inherited url property of the Application and the one you declared so do the following..
    var _url:URLRequest = new URLRequest("myXML.xml");
    var xml:XML;
    var rss:URLLoader = new URLLoader();
    rss.load(_url);
    Thanks,
    Bhasker

  • How to parse xml string using JSTL

    Suppose this is my string:-----
    <books>
    <book>
    <title id=1>Book Title A</title>
    <author>A. B. C.</author>
    <price>17.95</price>
    </book>
    <book>
    <title id=2>Book Title B</title>
    <author>X. Y. Z.</author>
    <price>24.99</price>
    </book>
    </books>
    and I want to read title id = 1 then, how to parse it, I found tutorials regarding parsing simple xml document but how to parse attributes of a given XML

    But both of them either parse a file or data from an input source. I don't think they handle strings.An InputSource can be constructed with a Reader as input. One useful subclass of Reader is StringReader, so you'd use something likeDocument doc = documentBuilder.parse(new InputSource(new StringReader(myXMLString)));

  • Ned help parsing XML

    I have an XML result that is coming back with aliases. I am
    parsing this data and putting each element into a database. A
    sample of the XML Structure is attached. I am using the ARRAYLEN
    feature to count the child elements but that generates an error.
    How can I get an accurate count of the <ALIAS> element in
    this XML so I now how many times to loop through that set of
    elements?
    Thanks

    if you use cfhttp to read the xml into a variable and then
    CFDUMP it, you will be able to see all the variables that CF uses
    in XML parsing, including the ones in your file and the ones you
    need to access the nested variables.
    This is code from an app I use to run through a list of games
    played from Halo2 using Bungie's XML feed to CF.
    This will likely give you a good starting point.

  • How to ignore white space when parse xml document using xerces 2.4.0

    When I run the program with the xml given below the following error comes.
    Problem parsing the file.java.lang.NullPointerExceptionjava.lang.NullPointerExce
    ption
    at SchemaTest.main(SchemaTest.java:25)
    ============================================================
    My expectation is "RECEIPT". Pls send me the solution.
    import org.apache.xerces.parsers.DOMParser;
    import org.xml.sax.InputSource;
    import java.io.*;
    import org.xml.sax.ErrorHandler;
    import org.w3c.dom.*;
    public class SchemaTest {
    public static void main (String args[])
    try
    FileInputStream is = new FileInputStream(new File("C:\\ADL\\imsmanifest.xml"));
    InputSource in = new InputSource(is);
    DOMParser parser = new DOMParser();
    //parser.setFeature("http://xml.org/sax/features/validation", false);
    //parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", "memory.xsd");
    //ErrorHandler errors = new ErrorHandler();
    //parser.setErrorHandler(errors);
    parser.parse(in);
    Document manifest = parser.getDocument();
    manifest.normalize();
    NodeList nl = manifest.getElementsByTagName("organization");
    System.out.println((((nl.item(0)).getChildNodes()).item(0)).getFirstChild().getNodeValue());
    catch (Exception e)
    System.out.print("Problem parsing the file."+e.toString());
    e.printStackTrace();
    <?xml version = '1.0'?>
    <organizations default="detail">
    <organization identifier="detail" isvisible="true">
    <title>RECEIPT</title>
    <item identifier="S100000" identifierref="R100000" isvisible="true">
    <title>Basic Module</title>
    <item identifier="S100001" identifierref="R100001" isvisible="true">
    <title>Objectives</title>
    <metadata/>
    </item>
    </item>
    <metadata/>
    </organization>
    </organizations>
    Is there a white space problem? How do I get rid from this problem.

    ok now i really wrote the whole code, a bit scrolling in the API is to hard?
                DocumentBuilderFactory dbf = new DocumentBuilderFactory();
                DocumentBuilder db = dbf.newDocumentBuilder();
                dbf.setNamespaceAware(true); //or set false
                Document d = db.parse(inputstream);

  • Parse XML by using NSXMLDocument

    I know how to parse external file or an URL XML, but what if I have a string - NSString that contains XML data, how should I do to let NSXMLDocument prase this string?
    thank you.
    G5   Mac OS X (10.4)  

    I don't get your problem either. An element doesn't have a length. Perhaps you need the length of the text of the TextNode that is the only child of your AttributeValue element?

  • Problem while parsing xml file using DOM

    I have a xml file NewXML.xml. When I parse it I'm not getting the expected output: I'm trying to get only the value of the "name" tag. When I tried getElementByTagName("name"), I'm not getting the expected result.
    Here is my xml file based on a schema
    <?xml version="1.0" encoding="UTF-8"?>
    <student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NewXMLSchema.xsd">
    <name>john</name>
    <id>1000</id>
    </student>
    Coding:
    public static void main(String argv[])
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    Document document ;
    try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( "NewXML.xml" );
    NodeList nodeList = (document.getElementsByTagName("name") );
    System.out.println(nodeList.getLength()+" node list "+nodeList.item(0));
    System.out.println(nodeList.item(0).getNodeValue());
    NodeList nodeList1 = nodeList.item(0).getChildNodes();
    System.out.println(nodeList1.getLength()+" node list "+nodeList1.item(0));
    System.out.println(nodeList1.item(0).getNodeValue());
    When I ran the above coding I got:
    1 node list [name: null]
    null
    1 node list [#text: name]
    name
    What should I do to get the result "john" inorder to change it
    Thanks
    rathi

    System.out.println(nodeList.item(0).getFirstChild().getNodeValue());

  • Importing/Parsing XML using SQL and/or PL/SQL

    What is the recomended way of importing/parsing XML data using SQL and/or PL/SQL?
    I have an XSD that defines the structure of the file, and an XML file that has the content in the appropriate structure. I have parsed (checked) the structure of the XML file using JDOM in my java application, and then passed it to a function in a package on the database as a CLOB.
    What I need to do is parse the contents of the XML file that is passed into the function and extract the values of each XML element so that I can then do some appropriate validation before inserting and committing the data to the database (hence completing the import function).
    A DBA colleague of mine has been experimenting with various ways of acheiving this, but has encountered a number of problems along the way, one of which being that he thinks that it is not possible to parse XML elements that are nested more than four levels deep - is this the case?
    The structure of the XSD/XML that the database function needs to manipulate and import data from is very complex (and recursive by it's nature).
    I would appreciate any suggestions as to how I can achieve the above in the most efficient manner.
    Thanks in advance for your help
    David

    This is the forum for the SQLDeveloper tool. You will get better answers in the SQL and PL/SQL forum, and especially the XML DB forum.
    Oracle has comprehensive and varied support for XML, including a PL/SQL parser.

  • Problem in parsing XML Schema

    I am trying to parse XML Schema using XSOM. The Schema has <xs:include>s
    e.g. I have first.xsd which includes second.xsd and second.xsd again includes third.xsd.
    First.xsd
    <xs:include schemaLocation="../Second.xsd">....
    Second.xsd
    <xs:include schemaLocation="Third.xsd">....
    When I parse "First.xsd" parser passes the correct path "C:/XSDSchema/Second.xsd"(First.xsd resides in "C:/XSDSchema/Schema/") to the EntityResolver's resolveEntity method. But for Second.xsd it passes "Third.xsd" only (Third.xsd resides in "C:/XSDSchema/" ) .
    Any Idea ?????

    Here is a screenshort of the part of my workflow:
    In the mappings of the "Set Value" activity, I have one line with those properties:
    Location: /process_data/bonusValidationForm/object/data/xdp/datasets/data/BonusValidationForm/buMan agerID
    Expression: /process_data/currentUser/object/@userId
    Where:
    bonusValidationForm is a process variable of my workflow that point my xdp form
    buManagerID is the textfield I want to set
    currentUser is a process variable (type User) that was well setted by the task Find BU Manager

  • How to parse xml in java

    i wrote java client to invoke webservice(TIBCO) as a result i am getting back xml. now i have to parse xml and use the information. can anyone pls advise on this.
    thanks

    There are two kinds of parser available. One converts the XML to a Document Object Model (DOM). This is a heirarchy of Node objects each of which represents an element of XML, a tag, an attribute a piece of text etc.. Then you walk the graph extracting what you want.
    The other kind is the SAX event parser. You give this a callback (extends DefaultHandler) and it calls appropriate methods for each element as it's encountered.
    The second method is probably slight more complex to use but will deal with files of unlimited size without huge memory usage.
    In both cases you get the parser using a Factory/Interface pattern. You'll find the factory classes in javax.xml.parsers. The rest of the DOM stuff is in org.w3c.dom and the SAX stuff in org.xml.sax.

  • How parse xml in java

    i wrote java client to invoke webservice(TIBCO) as a result i am getting back xml. now i have to parse xml and use the information. can anyone pls advise on this.
    thanks

    Cross-post
    http://forum.java.sun.com/thread.jspa?threadID=706827

  • Couldn't parse image from XML file using NSXMLParser

    Hi all, Since i am newbie to developing iPhone application, i have problem in parsing XML data.
    I use the following code for parsing XML file, this is RootViewController.h file
    #import <UIKit/UIKit.h>
    #import "SlideMenuView.h"
    #define kNameValueTag 1
    #define kColorValueTag 2
    #define kSwitchTag 100
    @class DetailViewController;
    @interface RootViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
    DetailViewController *detailViewController;
    UITableView *myTable;
    UIActivityIndicatorView *activityIndicator;
    UIButton *btn;
    CGSize cellSize;
    NSXMLParser *rssParser;
    NSMutableArray *stories;
    NSMutableDictionary *item;
    NSString *currentElement;
    NSMutableString *currentTitle, *currentDate, *currentSummary, *currentLink, *currentImage;
    SlideMenuView *slideMenu;
    NSMutableArray *buttonArray;
    UIButton *rubic;
    UIButton *buurt;
    UIButton *beeld;
    UILabel *lbl;
    NSString *url;
    @property (nonatomic, retain) UITableView *myTable;
    @property (nonatomic, retain) DetailViewController *detailViewController;
    @property (nonatomic, retain) SlideMenuView *slideMenu;
    @property (nonatomic, retain) UIButton *btn;
    @property (nonatomic, retain) NSMutableArray *buttonArray;
    @property (nonatomic, retain) UIButton *rubic;
    @property (nonatomic, retain) UIButton *buurt;
    @property (nonatomic, retain) UIButton *beeld;
    @property (nonatomic, retain) UILabel *lbl;
    @end
    below is the RootViewController.m file,
    #import <Foundation/Foundation.h>
    #import "RootViewController.h"
    #import "DetailViewController.h"
    #import "SlideMenuView.h"
    @implementation RootViewController
    @synthesize rubic, buurt, beeld, detailViewController, myTable, btn, buttonArray, slideMenu, lbl;
    - (void)parseXMLFileAtURL:(NSString *)URL {
    stories = [[NSMutableArray alloc] init];
    //you must then convert the path to a proper NSURL or it won't work
    NSURL *xmlURL = [NSURL URLWithString:URL];
    // here, for some reason you have to use NSClassFromString when trying to alloc NSXMLParser, otherwise you will get an object not found error
    // this may be necessary only for the toolchain
    rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
    // Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
    [rssParser setDelegate:self];
    // Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
    [rssParser setShouldProcessNamespaces:NO];
    [rssParser setShouldReportNamespacePrefixes:NO];
    [rssParser setShouldResolveExternalEntities:NO];
    [rssParser parse];
    - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
    NSString * errorString = [NSString stringWithFormat:@"Unable to download story feed from web site (Error code %i )", [parseError code]];
    NSLog(@"error parsing XML: %@", errorString);
    UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    //NSLog(@"found this element: %@", elementName);
    currentElement = [elementName copy];
    if ([elementName isEqualToString:@"item"]) {
    // clear out our story item caches...
    item = [[NSMutableDictionary alloc] init];
    currentTitle = [[NSMutableString alloc] init];
    currentDate = [[NSMutableString alloc] init];
    currentSummary = [[NSMutableString alloc] init];
    currentLink = [[NSMutableString alloc] init];
    currentImage = [[NSMutableString alloc] init];
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
    //NSLog(@"ended element: %@", elementName);
    if ([elementName isEqualToString:@"item"]) {
    // save values to an item, then store that item into the array...
    [item setObject:currentTitle forKey:@"title"];
    [item setObject:currentSummary forKey:@"summary"];
    [item setObject:currentDate forKey:@"date"];
    [item setObject:currentImage forKey:@"enclosure"];
    [stories addObject:[item copy]];
    NSLog(@"adding story: %@", currentTitle);
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    //NSLog(@"found characters: %@", string);
    // save the characters for the current item...
    if ([currentElement isEqualToString:@"title"]) {
    [currentTitle appendString:string];
    } else if ([currentElement isEqualToString:@"description"]) {
    [currentSummary appendString:string];
    } else if ([currentElement isEqualToString:@"pubDate"]) {
    [currentDate appendString:string];
    } else if ([currentElement isEqualToString:@"enclosure"]) {
    [currentImage appendString:string];
    - (void)parserDidEndDocument:(NSXMLParser *)parser {
    [activityIndicator stopAnimating];
    [activityIndicator removeFromSuperview];
    NSLog(@"all done!");
    NSLog(@"stories array has %d items", [stories count]);
    [myTable reloadData];
    - (void)loadView {
    //self.title = @"GVA_iPhone";
    //UIImage *img = [UIImage imageNamed: @"gva_v2.1.png"];
    CGRect frame = [[UIScreen mainScreen] bounds];
    UIView *aView = [[UIView alloc] initWithFrame:frame];
    aView.backgroundColor = [UIColor grayColor];
    self.view = aView;
    [aView release];
    lbl = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 33.0, 320.0, 30.0)];
    lbl.backgroundColor = [UIColor colorWithRed:21.0/255.0 green:113.0/255.0 blue:194.0/255.0 alpha:1.0];
    lbl.textColor = [UIColor whiteColor];
    lbl.font = [UIFont boldSystemFontOfSize:18.0];
    [self.view addSubview:lbl];
    [lbl release];
    buttonArray = [[NSMutableArray alloc] init];
    for(int i = 1; i < 4; i++)
    // Rounded rect is nice
    //UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    // Give the buttons a width of 100 and a height of 30. The slide menu will take care of positioning the buttons.
    // If you don't know that 100 will be enough, use my function to calculate the length of a string. You find it on my blog.
    [btn setFrame:CGRectMake(0.0f,3.0f, 120.0f, 30.0f)];
    switch(i){
    case 1:
    [btn setTitle:[NSString stringWithFormat:@" Snel", i+1] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"topbg02.png"] forState:UIControlStateNormal];
    lbl.text = @" Snel";
    [btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [buttonArray addObject:btn];
    break;
    case 2:
    [btn setTitle:[NSString stringWithFormat:@" Binnenland", i+1] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"topbg02.png"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [buttonArray addObject:btn];
    break;
    case 3:
    [btn setTitle:[NSString stringWithFormat:@" Buitenland", i+1] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"topbg02.png"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
    [buttonArray addObject:btn];
    break;
    [btn release];
    slideMenu = [[SlideMenuView alloc]initWithFrameColorAndButtons:CGRectMake(0.0, 3.0, 330.0, 30.0) backgroundColor:[UIColor blackColor] buttons:buttonArray];
    [self.view addSubview:slideMenu];
    UITableView *aTableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 63.0, 320.0, 310.0)];
    aTableView.dataSource = self;
    aTableView.delegate = self;
    aTableView.rowHeight = 120;
    self.myTable = aTableView;
    [aTableView release];
    [self.view addSubview:myTable];
    rubic = [[UIButton alloc]initWithFrame:CGRectMake(0.0, 370.0, 105.0, 50.0)];
    [rubic setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rubic setBackgroundImage:[UIImage imageNamed:@"MOUSEOVER.png"] forState:UIControlStateNormal];
    [rubic addTarget:self action:@selector(buttonBinn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:rubic];
    UILabel *lblRub = [[UILabel alloc]initWithFrame:CGRectMake(10.0, 385.0, 45.0, 12.0)];
    lblRub.text = @"Rubriek";
    lblRub.font = [UIFont boldSystemFontOfSize:11.0];
    lblRub.backgroundColor = [UIColor clearColor];
    lblRub.textColor = [UIColor whiteColor];
    [self.view addSubview:lblRub];
    UIImageView *imgCat = [[UIImageView alloc] initWithFrame:CGRectMake(58.0, 375.0, 39.0, 36.0)];
    imgCat.image = [UIImage imageNamed:@"category_icon.png"];
    [self.view addSubview:imgCat];
    buurt = [[UIButton alloc] initWithFrame:CGRectMake(105.0, 370.0, 108.0, 50.0)];
    [buurt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [buurt setBackgroundImage:[UIImage imageNamed:@"bottombg01.png"] forState:UIControlStateNormal];
    [buurt addTarget:self action:@selector(buttonBuurt:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buurt];
    UILabel *lblGlo = [[UILabel alloc]initWithFrame:CGRectMake(112.0, 385.0, 59.0, 12.0)];
    lblGlo.text = @"In de Buurt";
    lblGlo.font = [UIFont boldSystemFontOfSize:11.0];
    lblGlo.backgroundColor = [UIColor clearColor];
    lblGlo.textColor = [UIColor whiteColor];
    [self.view addSubview:lblGlo];
    UIImageView *imgGlo = [[UIImageView alloc] initWithFrame:CGRectMake(173.0, 375.0, 39.0, 36.0)];
    imgGlo.image = [UIImage imageNamed:@"globe_icon.png"];
    [self.view addSubview:imgGlo];
    beeld = [[UIButton alloc]initWithFrame:CGRectMake(213.0, 370.0, 108.0, 50.0)];
    [beeld setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [beeld setBackgroundImage:[UIImage imageNamed:@"bottombg01.png"] forState:UIControlStateNormal];
    [beeld addTarget:self action:@selector(buttonBeeld:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:beeld];
    UILabel *lblCam = [[UILabel alloc]initWithFrame:CGRectMake(228.0, 385.0, 45.0, 12.0)];
    lblCam.text = @"In Beeld";
    lblCam.font = [UIFont boldSystemFontOfSize:11.0];
    lblCam.backgroundColor = [UIColor clearColor];
    lblCam.textColor = [UIColor whiteColor];
    [self.view addSubview:lblCam];
    UIImageView *imgCam = [[UIImageView alloc] initWithFrame:CGRectMake(276.0, 375.0, 39.0, 36.0)];
    imgCam.image = [UIImage imageNamed:@"camera_icon.png"];
    [self.view addSubview:imgCam];
    if([stories count] == 0) {
    [self parseXMLFileAtURL:@"http://iphone.concentra.exuvis.com/feed/rss/article/2/binnenland.xml"];
    cellSize = CGSizeMake([myTable bounds].size.width,60);
    - (IBAction)buttonPressed:(id)sender {
    lbl.text = ((UIButton*)sender).currentTitle;
    - (IBAction)buttonClicked:(id)sender {
    lbl.text = ((UIButton*)sender).currentTitle;
    - (IBAction)buttonTouched:(id)sender {
    lbl.text = ((UIButton*)sender).currentTitle;
    -(void)buttonBinn:(id)sender
    [rubic setBackgroundImage:[UIImage imageNamed:@"MOUSEOVER.png"] forState:UIControlStateNormal];
    [buurt setBackgroundImage:[UIImage imageNamed:@"bottombg01.png"] forState:UIControlStateNormal];
    [beeld setBackgroundImage:[UIImage imageNamed:@"bottombg01.png"] forState:UIControlStateNormal];
    -(void)buttonBuurt:(id)sender
    [buurt setBackgroundImage:[UIImage imageNamed:@"MOUSEOVER.png"] forState:UIControlStateNormal];
    [beeld setBackgroundImage:[UIImage imageNamed:@"bottombg01.png"] forState:UIControlStateNormal];
    [rubic setBackgroundImage:[UIImage imageNamed:@"bottombg01.png"] forState:UIControlStateNormal];
    -(void)buttonBeeld:(id)sender
    [beeld setBackgroundImage:[UIImage imageNamed:@"MOUSEOVER.png"] forState:UIControlStateNormal];
    [rubic setBackgroundImage:[UIImage imageNamed:@"bottombg01.png"] forState:UIControlStateNormal];
    [buurt setBackgroundImage:[UIImage imageNamed:@"bottombg01.png"] forState:UIControlStateNormal];
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
    - (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
    - (void)dealloc {
    [myTable release];
    [detailViewController release];
    [super dealloc];
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [stories count];
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GVAiPhone"];
    if (cell == nil) {
    //CGRect cellFrame = CGRectMake(0, 0, 300, 65);
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"GVAiPhone"] autorelease];
    //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    //cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_icon.png"]];
    CGRect nameValueRect = CGRectMake(5, 5, 275, 35);
    UILabel *nameValue = [[UILabel alloc] initWithFrame:nameValueRect];
    nameValue.tag = kNameValueTag;
    nameValue.font = [UIFont fontWithName:@"Arial" size:15.0];
    nameValue.lineBreakMode = UILineBreakModeWordWrap;
    nameValue.numberOfLines = 2;
    [cell.contentView addSubview:nameValue];
    [nameValue release];
    CGRect colorValueRect = CGRectMake(5, 38, 275, 65);
    UILabel *colorValue = [[UILabel alloc] initWithFrame:colorValueRect];
    colorValue.tag = kColorValueTag;
    colorValue.font = [UIFont fontWithName:@"Arial" size:11.0];
    colorValue.textColor = [UIColor colorWithRed:130.0/255.0 green:135.0/255.0 blue:139.0/255.0 alpha:1.0];
    colorValue.lineBreakMode = UILineBreakModeWordWrap;
    colorValue.textAlignment = UITextAlignmentLeft;
    colorValue.numberOfLines = 6;
    [cell.contentView addSubview:colorValue];
    [colorValue release];
    // Set up the cell
    //cell.text = [theSimpsons objectAtIndex:indexPath.row];
    //cell.hidesAccessoryWhenEditing = YES;
    NSUInteger storyIndex = [indexPath row];
    NSDictionary *rowData = [stories objectAtIndex:storyIndex];
    UILabel *name = (UILabel *)[cell.contentView viewWithTag:kNameValueTag];
    name.text = [rowData objectForKey:@"title"];
    //name.lineBreakMode;
    //UIImage *image =[UIImage imageNamed: currentImage];imageWithContentsOfFile
    //image.size.width = 50;
    //iimage.size.height = 50;
    //cell.image = [UIImage imageNamed:currentImage];
    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_icon.png"]];
    UILabel *color = (UILabel *)[cell.contentView viewWithTag:kColorValueTag];
    color.text = [rowData objectForKey:@"summary"];
    return cell;
    @end
    - here the actual problem is the xml node <enclosure> contains images but in using the method "didEndElement" , it doesn't parse into the <enclosure> node. ya so please help me in parsing and getting the image.
    Waiting for your help !!
    -Sathiya

    Hi, how did you solve your problem in detail. I'm having the same problem with this rss-feed: www.spiegel.de/index.rss
    I cannot parse the url of the images. I'm looking forward to your answer.

Maybe you are looking for

  • Full update not getting all records from PSA to ODS

    Dear BW Masters, I am working with MM module. Iam using standard extract structure 2LIS_02_ACC Iam doing full update. Getting full data 1300 records in to PSA. But getting only 298 in to my ODS. I tried changing fields in to KEY FIELDS AND IN TO DATA

  • AIR Installers fail to install on Lion 10.7

    This happens every time, including trying to install the older versions. I've removed everything, tried chmod 777 my app folders, etc. nothing works. Ideas? 1/30/12 4:27:00.445 PM Adobe AIR Installer: Runtime Installer begin with version 3.1.0.4880 o

  • Unlock canvas in Fireworks CS3?

    Is it possible to unlock the canvas so you can pull it around in full window mode like you can in photoshop and illustrator?  if i have an object in the upper right corner of my document, I want to be able to drag the whole window to the center of th

  • Can´t start After Effects

    Hi, if I try to start After Effects (I have the Student & Teacher Cloud) I got a Systemerror, that "LogSession.dll" would be missing, and I had to install it again. But by using die Apllication Manager, I can´t install it. Can anybody tell me, where

  • What version of Quicktime Player X is updated to if updating to 10.7.5?

    Does anyone know what version of Quicktime Player X is updated to when you update the OS to 10.7.5? Currently, I am running Quicktime Player 10.1, but wasn't sure if it would stay at 10.1 or get updated to 10.2. Also, has it been verified that Quickt