473,480 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Create 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="http://www.w3.org/1999/xhtml">
<a>a</a>
<b>b</b>
<content>Lorem 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 2318
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.html_ns+'">'+textarea.val()+'</description>';
// code for IE
if (window.ActiveXObject){
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(xmlString);
}
// code for Mozilla, Firefox, Opera, etc.
else{
var parser=new DOMParser();
var xmlDoc=parser.parseFromString(xmlString,"text/xml");
}

var root=xmlDoc.documentElement;
root = el.ownerDocument.importNode(root,true);//el is the element where we'd
like to put this junk
while(root.hasChildNodes()){
el.appendChild(root.removeChild(root.firstChild));
}

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
2745
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()...
3
3045
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...
1
1504
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...
0
2356
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...
2
14702
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...
3
17226
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...
3
4350
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...
7
2051
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...
13
4473
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...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7076
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...
0
6873
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...
0
5321
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,...
0
2990
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...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
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 ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
174
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...

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.