Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #9507 > unrolled thread
| Started by | Magnus Warker <magnux@mailinator.com> |
|---|---|
| First post | 2011-11-04 06:12 +0100 |
| Last post | 2011-11-04 18:20 -0700 |
| Articles | 10 — 5 participants |
Back to article view | Back to comp.lang.java.programmer
includes in xml-files? Magnus Warker <magnux@mailinator.com> - 2011-11-04 06:12 +0100
Re: includes in xml-files? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-04 15:51 -0700
Re: includes in xml-files? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-11-04 20:20 -0300
Re: includes in xml-files? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-04 17:46 -0700
Re: includes in xml-files? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-11-04 22:58 -0300
Re: includes in xml-files? Arne Vajhøj <arne@vajhoej.dk> - 2011-11-04 20:14 -0400
Re: includes in xml-files? Arne Vajhøj <arne@vajhoej.dk> - 2011-11-04 21:32 -0400
Re: includes in xml-files? Jeff Higgins <jeff@invalid.invalid> - 2011-11-04 20:41 -0400
Re: includes in xml-files? Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-11-04 23:00 -0300
Re: includes in xml-files? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-04 18:20 -0700
| From | Magnus Warker <magnux@mailinator.com> |
|---|---|
| Date | 2011-11-04 06:12 +0100 |
| Subject | includes in xml-files? |
| Message-ID | <j8vs8h$bah$1@news.m-online.net> |
Hi, I have an XML-File in the classpath and I read it in with getResourceAsStream (Pseudocode): InputStream stm = class.getResourceAsStream (...); DocumentBuilderFactory ftr = DocumentBuilderFactory.newInstance (); ftr.setIgnoringComments (true); DocumentBuilder bld = ftr.newDocumentBuilder(); Document doc = bld.parse (stm); Now I would like to source out some of the contents into separate xml-files and include them into the main file. Is this possible, in particular when the files are loaded as resource stream? How can I do that? WhatÄs the syntax for the include directives? Thanks Magnus
[toc] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2011-11-04 15:51 -0700 |
| Message-ID | <hiq8b7talkbfmqmfn837vrd06trnhkd2dt@4ax.com> |
| In reply to | #9507 |
On Fri, 04 Nov 2011 06:12:52 +0100, Magnus Warker <magnux@mailinator.com> wrote, quoted or indirectly quoted someone who said : >How can I do that? WhatÄs the syntax for the include directives? I have nested includes in the HTMLMacros processor. You need an Include object that keeps track of the mother file and where you were in it, or simply do it with recursive calls with that info tracked in local variables. What syntax? I have never heard of anything part of the XML protocol. If you want to be able to include in the middle of a field you will need something that won't be confused with data. You could do it with something that looked a bit like real XML e.g. <include "file.txt" /> (which can even appear in the middle of a field or between XML tags. The embedded text need not contain balanced tags. You might want to decorate it a bit to avoid conflicting with real xml e.g. <@include "file.txt" /> You might want to make it look more like real XML, e.g. <include file="file.txt /> or <@include>file.txt</@include> You might to make it look like perfectly legit XML so the XML parser will find and parse the commands for you. Otherwise you will have to look ahead yourself or preprocess the file to create the complet file before feeding it to the XML processor. -- Roedy Green Canadian Mind Products http://mindprod.com Capitalism has spurred the competition that makes CPUs faster and faster each year, but the focus on money makes software manufacturers do some peculiar things like deliberately leaving bugs and deficiencies in the software so they can soak the customers for upgrades later. Whether software is easy to use, or never loses data, when the company has a near monopoly, is almost irrelevant to profits, and therefore ignored. The manufacturer focuses on cheap gimicks like dancing paper clips to dazzle naive first-time buyers. The needs of existing experienced users are almost irrelevant. I see software rental as the best remedy.
[toc] | [prev] | [next] | [standalone]
| From | Arved Sandstrom <asandstrom3minus1@eastlink.ca> |
|---|---|
| Date | 2011-11-04 20:20 -0300 |
| Message-ID | <Eq_sq.15572$SW4.9194@newsfe08.iad> |
| In reply to | #9507 |
On 11-11-04 02:12 AM, Magnus Warker wrote: > Hi, > > I have an XML-File in the classpath and I read it in with > getResourceAsStream (Pseudocode): > > InputStream stm = class.getResourceAsStream (...); > DocumentBuilderFactory ftr = DocumentBuilderFactory.newInstance (); > ftr.setIgnoringComments (true); > DocumentBuilder bld = ftr.newDocumentBuilder(); > Document doc = bld.parse (stm); > > Now I would like to source out some of the contents into separate > xml-files and include them into the main file. > > Is this possible, in particular when the files are loaded as resource > stream? > > How can I do that? WhatÄs the syntax for the include directives? > > Thanks > Magnus One standard way of including XML is external parsed entities. See http://www.w3.org/TR/2004/REC-xml-20040204/#sec-external-ent. If you've done that then there is actually no other coding that you need to do. Simply continue to reference the main XML that includes other XML; the parser is responsible for locating and parsing the includes. AHS -- You should know the problem before you try to solve it. Example: When my son was three he cried about a problem with his hand. I kissed it several times and asked him about the problem. He peed on his hand. -- Radia Perlman, inventor of spanning tree protocol
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2011-11-04 17:46 -0700 |
| Message-ID | <qo19b71rec956hpvg79lks0mtst4euel36@4ax.com> |
| In reply to | #9541 |
On Fri, 04 Nov 2011 20:20:02 -0300, Arved Sandstrom <asandstrom3minus1@eastlink.ca> wrote, quoted or indirectly quoted someone who said : >One standard way of including XML is external parsed entities. See >http://www.w3.org/TR/2004/REC-xml-20040204/#sec-external-ent. I am amazed you deduced that lawyerly document anything to with including text in XML files. -- Roedy Green Canadian Mind Products http://mindprod.com Capitalism has spurred the competition that makes CPUs faster and faster each year, but the focus on money makes software manufacturers do some peculiar things like deliberately leaving bugs and deficiencies in the software so they can soak the customers for upgrades later. Whether software is easy to use, or never loses data, when the company has a near monopoly, is almost irrelevant to profits, and therefore ignored. The manufacturer focuses on cheap gimicks like dancing paper clips to dazzle naive first-time buyers. The needs of existing experienced users are almost irrelevant. I see software rental as the best remedy.
[toc] | [prev] | [next] | [standalone]
| From | Arved Sandstrom <asandstrom3minus1@eastlink.ca> |
|---|---|
| Date | 2011-11-04 22:58 -0300 |
| Message-ID | <eL0tq.8245$V07.7551@newsfe22.iad> |
| In reply to | #9546 |
On 11-11-04 09:46 PM, Roedy Green wrote: > On Fri, 04 Nov 2011 20:20:02 -0300, Arved Sandstrom > <asandstrom3minus1@eastlink.ca> wrote, quoted or indirectly quoted > someone who said : > >> One standard way of including XML is external parsed entities. See >> http://www.w3.org/TR/2004/REC-xml-20040204/#sec-external-ent. > > I am amazed you deduced that lawyerly document anything to with > including text in XML files. Well, truth be told, I thought it was pretty obvious. :-) The link you supplied to that one section of Dave Pawson's site, if you left out the XSLT stuff, bears that out (Jeni Tennison's answer that you referenced in particular). It's not so much that I had to investigate the XML spec to find this, I already knew about it - I thought it was commonplace knowledge. The entity approach has the advantage of being part of the XML spec. Now Magnus mentioned external XML files so that's why I referenced external parsed entities specifically. I won't disparage XInclude. It has advantages, notably not needing to pre-declare external entities in the DTD (which may or may not be an issue for Magnus). Section 1.2 in http://www.w3.org/TR/xinclude/ should be read when deciding between the two approaches. On the subject of XInclude, if the OP wished to try that approach to use something like <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="inclusion.xml" parse="xml" /> (the parse="xml" is the default actually) then he can modify his original code with ftr.setXIncludeAware(true); ftr.setNamespaceAware(true); and go to town. AHS -- You should know the problem before you try to solve it. Example: When my son was three he cried about a problem with his hand. I kissed it several times and asked him about the problem. He peed on his hand. -- Radia Perlman, inventor of spanning tree protocol
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-11-04 20:14 -0400 |
| Message-ID | <4eb47ff8$0$294$14726298@news.sunsite.dk> |
| In reply to | #9507 |
On 11/4/2011 1:12 AM, Magnus Warker wrote: > I have an XML-File in the classpath and I read it in with > getResourceAsStream (Pseudocode): > > InputStream stm = class.getResourceAsStream (...); > DocumentBuilderFactory ftr = DocumentBuilderFactory.newInstance (); > ftr.setIgnoringComments (true); > DocumentBuilder bld = ftr.newDocumentBuilder(); > Document doc = bld.parse (stm); > > Now I would like to source out some of the contents into separate > xml-files and include them into the main file. > > Is this possible, in particular when the files are loaded as resource > stream? > > How can I do that? WhatÄs the syntax for the include directives? XML is more a family of languages than it is a language. So I would expect includes to be done using an element specific for the particular XML dialect. This also means that the XML parser itself can not do the processing, but the application will need to handle that. Arne
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-11-04 21:32 -0400 |
| Message-ID | <4eb49234$0$295$14726298@news.sunsite.dk> |
| In reply to | #9544 |
On 11/4/2011 8:14 PM, Arne Vajhøj wrote: > On 11/4/2011 1:12 AM, Magnus Warker wrote: >> I have an XML-File in the classpath and I read it in with >> getResourceAsStream (Pseudocode): >> >> InputStream stm = class.getResourceAsStream (...); >> DocumentBuilderFactory ftr = DocumentBuilderFactory.newInstance (); >> ftr.setIgnoringComments (true); >> DocumentBuilder bld = ftr.newDocumentBuilder(); >> Document doc = bld.parse (stm); >> >> Now I would like to source out some of the contents into separate >> xml-files and include them into the main file. >> >> Is this possible, in particular when the files are loaded as resource >> stream? >> >> How can I do that? WhatÄs the syntax for the include directives? > > XML is more a family of languages than it is a language. > > So I would expect includes to be done using an element > specific for the particular XML dialect. > > This also means that the XML parser itself can not do > the processing, but the application will need to handle > that. XML schemas use: http://www.w3schools.com/schema/el_include.asp JSP pages use: http://java.sun.com/products/jsp/tags/12/syntaxref1214.html Facelets use: http://www.jsftoolbox.com/documentation/facelets/10-TagReference/facelets-ui-include.html etc.. Arne
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2011-11-04 20:41 -0400 |
| Message-ID | <j920mt$qfk$1@dont-email.me> |
| In reply to | #9507 |
On 11/04/2011 01:12 AM, Magnus Warker wrote: > Hi, > > I have an XML-File in the classpath and I read it in with > getResourceAsStream (Pseudocode): > > InputStream stm = class.getResourceAsStream (...); > DocumentBuilderFactory ftr = DocumentBuilderFactory.newInstance (); > ftr.setIgnoringComments (true); > DocumentBuilder bld = ftr.newDocumentBuilder(); > Document doc = bld.parse (stm); > > Now I would like to source out some of the contents into separate > xml-files and include them into the main file. > > Is this possible, in particular when the files are loaded as resource > stream? > > How can I do that? WhatÄs the syntax for the include directives? > XInclude? <http://www.w3.org/TR/xinclude/> I haven't used it, so I don't know how well it's supported. I think JAXP has some support.
[toc] | [prev] | [next] | [standalone]
| From | Arved Sandstrom <asandstrom3minus1@eastlink.ca> |
|---|---|
| Date | 2011-11-04 23:00 -0300 |
| Message-ID | <WM0tq.8246$V07.8094@newsfe22.iad> |
| In reply to | #9545 |
On 11-11-04 09:41 PM, Jeff Higgins wrote: > On 11/04/2011 01:12 AM, Magnus Warker wrote: >> Hi, >> >> I have an XML-File in the classpath and I read it in with >> getResourceAsStream (Pseudocode): >> >> InputStream stm = class.getResourceAsStream (...); >> DocumentBuilderFactory ftr = DocumentBuilderFactory.newInstance (); >> ftr.setIgnoringComments (true); >> DocumentBuilder bld = ftr.newDocumentBuilder(); >> Document doc = bld.parse (stm); >> >> Now I would like to source out some of the contents into separate >> xml-files and include them into the main file. >> >> Is this possible, in particular when the files are loaded as resource >> stream? >> >> How can I do that? WhatÄs the syntax for the include directives? >> > XInclude? <http://www.w3.org/TR/xinclude/> > I haven't used it, so I don't know how well it's supported. > I think JAXP has some support. > Certainly fine out of the box in 1.6, probably since 1.5. See my other post for turning on XInclude. AHS -- You should know the problem before you try to solve it. Example: When my son was three he cried about a problem with his hand. I kissed it several times and asked him about the problem. He peed on his hand. -- Radia Perlman, inventor of spanning tree protocol
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2011-11-04 18:20 -0700 |
| Message-ID | <mp39b71ps8cns7bf6htg2rde503u79clb0@4ax.com> |
| In reply to | #9507 |
On Fri, 04 Nov 2011 06:12:52 +0100, Magnus Warker <magnux@mailinator.com> wrote, quoted or indirectly quoted someone who said : >Hi, > >I have an XML-File in the classpath and I read it in with >getResourceAsStream (Pseudocode): > >InputStream stm = class.getResourceAsStream (...); >DocumentBuilderFactory ftr = DocumentBuilderFactory.newInstance (); >ftr.setIgnoringComments (true); >DocumentBuilder bld = ftr.newDocumentBuilder(); >Document doc = bld.parse (stm); > >Now I would like to source out some of the contents into separate >xml-files and include them into the main file. > >Is this possible, in particular when the files are loaded as resource >stream? > >How can I do that? WhatÄs the syntax for the include directives? Here are a couple of kludges. At least they are comprehensible. http://www.dpawson.co.uk/xsl/sect2/N4760.html#d6065e238 -- Roedy Green Canadian Mind Products http://mindprod.com Capitalism has spurred the competition that makes CPUs faster and faster each year, but the focus on money makes software manufacturers do some peculiar things like deliberately leaving bugs and deficiencies in the software so they can soak the customers for upgrades later. Whether software is easy to use, or never loses data, when the company has a near monopoly, is almost irrelevant to profits, and therefore ignored. The manufacturer focuses on cheap gimicks like dancing paper clips to dazzle naive first-time buyers. The needs of existing experienced users are almost irrelevant. I see software rental as the best remedy.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web