473,762 Members | 6,675 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing XML input from web form into namespaced xml file

I have a web form that will accept XML as input whose contents need to be
namespaced, and inserted into an XML document with a different namespace.

I need to take this:

Lorem ipsum dolor sit amet, consectetuer <a href="http://www.example.com "
title="etc" rel="whatever"> Link Here</aadipiscing elit. Vivamus molestie
dolor ultrices leo.

And stick it into this:

<root xmlns="http://some/default/ns"
xmlns:xhtml="ht tp://www.w3.org/1999/xhtml">
<a>a</a>
<b>b</b>
<content>Lore m ipsum dolor sit amet, consectetuer <xhtml:a
href="http://www.example.com " title="etc" rel="whatever"> Link Here</xhtml:a>
adipiscing elit. Vivamus molestie dolor ultrices leo.</content>
</root>
The form is being processed client side and the parent XML document is being
generated completely by Javascript using W3C XML DOM (need only work in
Firefox). The XML document is then POSTed to a PHP script that is doing
some additional processing to the xml document with SimpleXML and DOM.
Currently, the form contents are being added to the xml document and the xml
fragments are entity escaped. Any and all suggestions are welcome. Any
method of solution is acceptable (JavaScript, PHP, or XSLT, whatever works).
Just keep in mind the form contents must be namespaced differently from the
parent document namespace.

Thank you.
J.K
Apr 27 '07 #1
2 2336
Lorem ipsum dolor sit amet, consectetuer <a href="http://www.example.com "
title="etc" rel="whatever"> Link Here</aadipiscing elit. Vivamus molestie
dolor ultrices leo.
Well, the first problem is that this isn't a complete well-formed XML
document. It is well formed as an XML fragment, but that means that to
parse it you will probably to wrap a top-level element around it (which
can assert whatever default namespace you prefer, while you're at it),
parse that combined text, then take the output of that parse (minus the
wrapper element) and insert that into the appropriate point in the DOM
(using importNode to obtain nodes which are compatable with the tree you
want to insert them into). As long as the parse was namespace-aware, so
you get namespace-aware DOM nodes, all the right things should happen.

Can't help you with the string manipulation and parser invocation; I
don't do browser scripting, and I suspect Firefox doesn't yet support
the DOM3 load APIs (though I'd be glad to be wrong).

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Apr 28 '07 #2
Thanks. I don't know why I didn't think of that. My brain turns to mush
after hours of working on the same little thing. Here's out it finally
worked:

var xmlString = '<description
xmlns="'+twix.h tml_ns+'">'+tex tarea.val()+'</description>';
// code for IE
if (window.ActiveX Object){
var xmlDoc=new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.async="f alse";
xmlDoc.loadXML( xmlString);
}
// code for Mozilla, Firefox, Opera, etc.
else{
var parser=new DOMParser();
var xmlDoc=parser.p arseFromString( xmlString,"text/xml");
}

var root=xmlDoc.doc umentElement;
root = el.ownerDocumen t.importNode(ro ot,true);//el is the element where we'd
like to put this junk
while(root.hasC hildNodes()){
el.appendChild( root.removeChil d(root.firstChi ld));
}

If you have any comments on that, I'd love to hear them. It *looks* like
all that should work in IE but I'm not sure that importNode() is supported
yet. But it works in Fx so that's all I care!

Thanks again,
~J
Apr 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2769
by: Greg Wogan-Browne | last post by:
Hi all, I am having some trouble figuring out what is going on here - is this a bug, or correct behaviour? Basically, when I create an XML document with a namespace using xml.dom.minidom.parse() or parseString(), the namespace exists as an xmlns attribute in the DOM (fair enough, as it's in the original source document). However, if I use the DOM implementation to create an identical document with a namespace, the xmlns attribute is not...
3
3071
by: Girish | last post by:
Hi All, I have written a component(ATL COM) that wraps Xerces C++ parser. I am firing necessary events for each of the notifications that I have handled for the Content and Error handler. The events can then I am able to parse XML input in the form of files. I also have provided support for parsing of XML content in the form of string data. I am able to do so by creating a MemBufInputSource object using the XML content provided to the...
1
1510
by: Dan Corkum | last post by:
Good morning. I am working on an issue that is just baffling me. I have developed an .aspx page that receives an http form post that has a "file" attribute. When I do testing with a test post page, everything functions properly. When the actual customer does the post, the attribute following the "file" attribute is concatenated to the file itself. When I execute the HttpPostedFile.SaveAs(), the resulting file is what is sent Plus the...
0
2384
by: bruce | last post by:
hi... it appears that i'm running into a possible problem with mechanize/browser/python rgarding the "select_form" method. i've tried the following and get the error listed: br.select_form(nr = 1) br.select_form(name="foo") br.select_form(name=foo) br.select_form(name="foo")
2
14721
by: Cuong.Tong | last post by:
Greeting, Can anyone give me some hints about parsing the mulitpart/form-data stream? I have a form looks something like this <form action="process.dll> <input type=file name=fileupload</input> </form>
3
17381
by: Cuong.Tong | last post by:
Greeting, I am writing my own web server and having some problme parsing the the mulitpart/form-data stream that is sent from the browsers. I have a form looks something like this <form action="process.dll>
3
4386
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in the file) with the location. And for a particular section I parse only that section. The file is something like, .... DATAS
7
2068
by: programming | last post by:
Hi all, i have been having trouble with a login script that works on my windows machine, however when i upload it to the Unix server through VPN, the same script won't work! It won't parse member.txt properly i think. The password and usernames i am using are at the bottom of this post. Each time i go to login on the unix server, it clears the username and password field. I have been attempting to solve the problem, but have been...
13
4512
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple command set consisting of several single letter commands which take no arguments. A few additional single letter commands take arguments:
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.