472,983 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

xml/xpath parser problem

hi all!

can someone explain me why im getting this result?

this two <odjeljak<textshould be different

<?xml version='1.0' encoding='utf-8' ?>
<obrazac>
<odjeljak>
<odjeljak sifra="G.4"><red num="1"><text>III.1.4. Ostali posebni uvijeti za
izvršenje ugovora: (ako su određeni):</text></red><red num="2"><checkbox
id="1-1">Da</checkbox><checkbox id="1-2">Ne</checkbox></red><red
num="3"><text>Ako Da, opis posebnih uvjeta</text></red><red num="4"><unos
id="2-1" /></red></odjeljak>
</odjeljak>
<odjeljak>
<odjeljak sifra="G.4"><red num="1"><text>III.1.4. Ostali posebni uvijeti za
izvršenje ugovora: (ako su određeni):</text></red><red num="2"><checkbox
id="1-1">Da</checkbox><checkbox id="1-2">Ne</checkbox></red><red
num="3"><text>Ako Da, opis posebnih uvjeta</text></red><red num="4"><unos
id="2-1" /></red></odjeljak>
</odjeljak>
</obrazac>

N-16-M.xml
<odjeljci>
<odjeljak sifra="G.4">
<izmjena id="1">III.3.1. Izvršenje usluge je ograničeno na određenu
struku:</izmjena>
<izmjena id="2">Ako DA, upućivanje na odnosne pravne i upravne
propise:</izmjena>
</odjeljak>
<odjeljak sifra="G.4">
<izmjena id="1">III.1.4. Ostali posebni uvijeti za izvršenje ugovora: (ako
su određeni):</izmjena>
<izmjena id="2">Ako Da, opis posebnih uvjeta</izmjena>
</odjeljak>
</odjeljci>

odjeljci.xml
<odjeljci>
<odjeljak sifra="G.4">
<red num="1">
<text id="1" />
</red>
<red num="2">
<checkbox id="1-1">Da</checkbox>
<checkbox id="1-2">Ne</checkbox>
</red>
<red num="3">
<text id="2" />
</red>
<red num="4">
<unos id="2-1" />
</red>
</odjeljak>
</odjeljci>
public class GeneriranjeObrazaca
{
XmlDocument obrazac;
XmlDocument odjeljci;

XPathNavigator obrazacNavigator;
XPathNavigator odjeljciNavigator;
XPathNodeIterator obrazacIter;
XPathNodeIterator odjeljciIter;
XPathNodeIterator childrenIter;

XmlTextWriter xmlWriter;

string attrSifra;
string attrId;

public GeneriranjeObrazaca(string path)
{
obrazac = LoadXmlDoc(path);
obrazacNavigator = obrazac.CreateNavigator();
obrazacIter = obrazacNavigator.Select(@"/obrazac/odjeljak");

odjeljci = LoadXmlDoc(@"..\..\XML\Odjeljci.xml");
odjeljciNavigator = odjeljci.CreateNavigator();

xmlWriter = new XmlTextWriter(Console.Out);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteProcessingInstruction("xml", "version='1.0'
encoding='utf-8' ");
}

public XmlDocument LoadXmlDoc(string path)
{
XmlDocument doc;
try
{
doc = new XmlDocument();
doc.Load(path);
return doc;
}
catch (XmlException e)
{
Console.WriteLine(e.Message);
}
return null;
}

public void StvoriObrazac()
{
XmlDocument tempDoc = new XmlDocument();

xmlWriter.WriteStartElement("obrazac");
xmlWriter.WriteRaw("\n");

while (obrazacIter.MoveNext())
{
if (!obrazacIter.Current.HasAttributes)
{
//xmlWriter.WriteRaw(obrazacIter.Current.OuterXml);
//xmlWriter.WriteRaw("\n");
}
else if (obrazacIter.Current.HasAttributes &&
(!obrazacIter.Current.HasChildren))
{
attrSifra = obrazacIter.Current.GetAttribute("sifra", "");
odjeljciIter =
odjeljciNavigator.Select(@"//odjeljak[@sifra='" + attrSifra + "']");

while (odjeljciIter.MoveNext())
{
if (odjeljciIter.Current.GetAttribute("sifra", "") ==
attrSifra)
{
//xmlWriter.WriteRaw(odjeljciIter.Current.OuterXml);
//xmlWriter.WriteRaw("\n");
}
}
}
else if (obrazacIter.Current.HasAttributes &&
obrazacIter.Current.HasChildren)
{
attrSifra = obrazacIter.Current.GetAttribute("sifra", "");
int[] attrList = new int[2];

childrenIter =
obrazacNavigator.Select(@"//odjeljak[@sifra='" + attrSifra + "']/child::*");
odjeljciIter =
odjeljciNavigator.Select(@"//odjeljak[@sifra='" + attrSifra + "']");

odjeljciIter.MoveNext();

tempDoc.LoadXml(odjeljciIter.Current.OuterXml);

xmlWriter.WriteStartElement("odjeljak");
xmlWriter.WriteString("\n");

while (childrenIter.MoveNext())
{
if (childrenIter.Current.HasChildren)
{
if (childrenIter.Current.Name == "izmjena")
{
attrId =
childrenIter.Current.GetAttribute("id", "");

XmlNodeList nodeList =
tempDoc.GetElementsByTagName("*");

for (int i = 0; i < nodeList.Count; i++)
{
try
{
if (nodeList[i].Attributes["id"].Value
== attrId)
{
XmlNode root = nodeList[i].ParentNode;
XmlElement el =
tempDoc.CreateElement(nodeList[i].Name);
el.InnerText =
childrenIter.Current.Value;
root.ReplaceChild(el, nodeList[i]);
}
}
catch (NullReferenceException)
{ }
}
}
Jun 27 '08 #1
0 1144

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

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
2
by: Piet | last post by:
Hello, Via Xpath, I want to access nodes which have a namespace prefix. THe document at hand is an Xsl-FO document. I tried the following: from xml.dom import minidom from xml.xpath import...
3
by: Kevin | last post by:
I know this has probably been discussed many times before (I found answers when I searched yesterday), but I still can't get it to work... I have an attribute @OID that can contain any...
3
by: Johannes Koch | last post by:
Hi there, I'd like to apply an xpath to both HTML and XHTML documents. First I create a DOM document with a Java DOM parser, then apply the xpath with Xalan's XPathAPI class. The problem is that...
1
by: honky | last post by:
I didn't find any methods or classes for XPath. Does the xerces for c++ parser support XPath? If so, how should I use XPath with xerces api?
1
by: andy | last post by:
I am using XPath for the Electric XML Parser and having trouble getting simple XPath queries to work. The following query works: document.getElement(new...
3
by: abcd_68 | last post by:
Hi there, I'm using, for the first time, the JDK1.5 Xpath API. I need to find elements in a Hibernate-generated .hbm.xml file. These files come with a <!DOCTYPE header mentioning a remote URL....
4
by: Pyrus | last post by:
Hi, I'm new to the XPath thing and I found lots of expressions which usually only work correctly with XMLSpy (for some reason). I would like to copy a complete xml through an xpath (yes...
1
by: Floris Bruynooghe | last post by:
Hi I'm trying to use the .xpath('id("foo")') function on an lxml tree but can't get it to work. Given the following XML: <root><child id="foo"/></root> And it's XMLSchema: <?xml...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.