I've search the web for a solution. I am developing an application that fetches some xml content from a webserver. I can run the xml code in a log and every thing is returned OK. So that is working.
My problem is when it is time to parse the xml. My xml code looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<Content>
<Name>
John Doe
</Name>
<Adress>
Road 123
</Adress>
</Content>
How can grab the Name and the adress element and put the string "John Doe" and "Road 123" inside a string.
I hope someone can help me because i am really confused :s
Duplicate of many many many questions...
Try googling "XML Parsing iOS" - in fact please try googling your problem before posting any question on Stack Overflow.
Anyway, I'll give you a clue - have a look at NSXMLParser
Related
I'm trying to create a person in highrise using the API. I'm getting a "First name is missing. Contacts must have a name" error message in the response.
Here is my code:
let x = """<?xml version="1.0" encoding="UTF-8"?>
<person>
<first-name>name</first-name>
<last-name>last</last-name>
<contact-data>
<email-addresses type="array">
<email-address>
<address>someEmail#gmail.com</address>
</email-address>
</email-addresses>
</contact-data>
<tags type="array">
<tag>
<id type="integer">6154219</id>
<name>sometag</name>
</tag>
</tags>
</person>"""
let req = new RestRequest("/people.xml", Method.POST)
req.AddParameter("Content-Type", "application/xml")
req.AddParameter("application/xml", x, ParameterType.RequestBody)
let res = client.Execute(req)
The response returns a 422 Status code. Not sure what I'm doing wrong here?
Based on a similar StackOverflow question, it looks like you might get this error when there is something else wrong in your request, such as when it is missing the appropriate Content-Type.
I'm not familiar with Highrise or Restsharp to give a definite answer, but it seems that there might be something wrong with how you create the request. Just from reading your code, I find the use of AddParameter to add the body somewhat unexpected (even though it might be right). It looks like you might be able to use AddBody instead, so I'd try that.
(This is more of a comment than a proper answer, but it got too long to post it as a comment!)
I believe this is a result of attempting to add tags while creating the user. It's not at all clear from the API but at least in my experience no formulation of the tags field can be submitted with a company/person and succeed.
Alternatively, and I don't speak f# so I can't be sure, but the "Content-Type" is supposed to be in headers. Does the parameter component you're using add that explicitly as a header?
The missing name field showed up for me before I got the header working.
Turns out that you cannot add tags when creating a new person. It needs to added in a separate request after adding a contact. This is not explicitly mentioned in the documentation but can be concluded from their examples.
I'm new to learning Rails and currently trying to complete a project for school that involves using of XML along with an MVC architecture. I'm using Rails as my MVC and I just want to know how I should approach adding in the XML and then rendering it to display that information.
I know that xml.builder allows me to build the XML using more DRY philosophy but I'm looking for a good tutorial that would explain the process of doing that and then display it in my browser. Any information is appreciated. Thanks in advance.
You can use from_xml to parse XML data to hash:
xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<foo type="integer">1</foo>
<bar type="integer">2</bar>
</hash>
XML
hash = Hash.from_xml(xml)
# => {"hash"=>{"foo"=>1, "bar"=>2}}
Reading from a local file:
# reading the file content into a variable
xml_file = File.read("my_xml_file.xml")
hash = Hash.from_xml(xml_file)
Reference:
https://apidock.com/rails/v4.2.7/Hash/from_xml/class
I want to get xml string from url "http://test.php?value=xxx",here xxx shall be in XML format,for example:<request><command>test</command></request>.After I post this,the server will give me a result with xml string.But i don't know how to do that.Anyone has a solution?Thanks.
http://www.raywenderlich.com/30445/afnetworking-crash-course
That website gives you a step by step exactly what you need with AFNetworking. The question you are asking is very vague. If you get more specific then I can give direct code. Otherwise that crash course website is very informative.
I'm trying to convert an XML document into a Ruby hash for the first time, and having no success. I have my XML document, doc.xml, in a folder along with my script hashrunner.rb.
In hashrunner.rb:
require 'active_support/core_ext/hash'
hash = Hash.from_xml("doc.xml")
puts hash
The first line of the XML document is <?xml version="1.0" encoding="US-ASCII"?>, if that is helpful.
In my console, when I run ruby hashrunner.rb, I get the error message:
/Users/me/.rvm/gems/ruby-1.9.3-p374/gems/activesupport-4.0.0/lib/active_support/xml_mini/rexml.rb:34:in `parse':The document "doc.xml" does not have a valid root (REXML::ParseException)
As someone relatively new to Ruby, I don't understand what this means, and some internet searching didn't turn up an explanation, either. To start, I'm not even sure if I'm calling the XML file correctly in the from_xml method, so please let me know if that's the case. I'd be open to using different gems or a different approach if that would help.
I'm pretty sure Hash::from_xml has to take an XML string, not a filename string. Try:
hash = Hash.from_xml(File.read("doc.xml"))
Hoping that someone has some info on how to parse a xfa file. I can parse csv or xml files just fine, but an xfa one has come along and I'm not familar with the format. Looks like tab delimited body with column metadata at the top.
Anyone dealt with these before or can give me a steer on how to parse them?
I use vb.net but the language of any solution isn't too relevant.
Much appreciated.
Mmm, looks like nobody has a clue. The problem is that .xfa doesn't look like a "standard" extension: after all, anybody can create its own extension names, from .xyz to .something...
I looked around a bit, found, unsurprisingly (the 'x') an XML format with this extension, not much more.
Indicating where this kind of file come from, what kind of data it holds, might help. Or not.
You describe the file as being a simple TSV (tab separated values) with a header. It is quite trivial to parse, with a tokenizer or some regex, so I am not sure where you are stuck.
I think you might be talking about this: http://en.wikipedia.org/wiki/XFA_forms
This seemed to be a page that was designed to deal with that template: http://www.w3.org/1999/05/XFA/xfa-template-19990614
That information should be enough to get the ball rolling. If that fails then you can always analyse the file itself for patterns and go from there. I don't see it being too tricky.
Anyway, I hope that helps.
P.S. If you could provide a link to that .xfa we could probably give you more help.
The original post says the content looks like "tab delimited body with column metadata at the top". An XFA form doesn't look anything like that - XFA forms typically use a *.xdp extension and are XML.
Check out the Adobe page:
http://partners.adobe.com/public/developer/xml/index_arch.html
(Adobe XML Forms Architecture, currently 1400 pages)
Let LiveCycle/Acrobat parse it for you.