473,387 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1161

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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.