[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: DOM xml как создать header
vetalb91
Всем привет подскажите как создать xml документ с такой структурой ?
<?xml version="1.0" encoding="utf-8"?>
<HEADER>
<agentId>
201</agentId>
<agentname>
ООО "XXX"</agentname>
<agentadress>
Адрес/agentadress>
<metro></metro>
<coordinate></coordinate>
<creationDate>
2017-09-27 21:10:31</creationDate>
</HEADER>
<PRICES>
<priceItems>
<farmItemId>
1001508</farmItemId>
<quantity>
2</quantity>
<price>
143.80</price>
</priceItems>
<priceItems>
<farmItemId>
1001508</farmItemId>
<quantity>
2</quantity>
<price>
143.80</price>
</priceItems>
<priceItems>
<farmItemId>
1001508</farmItemId>
<quantity>
2</quantity>
<price>
143.80</price>
</priceItems>
</PRICES>


У меня эта структура получается но не могу создать элемент HEADER что бы он был выше PRICES
мне всю структуру не пишите просто скажите как создать HEADER элемент выше PRICES и чтобы он был получается независим от корня PRICES
Игорь_Vasinsky
точно так же.

создаешь ноду HEADER - добавляешб в древо.
потом в эту ноду добавляешь чилдренов.

как все добавил - создаёшь ноду PRICES и тоже самое

_____________
HTML, CSS (Bootstrap), JS(JQuery, ExtJS), PHP, MySQL, MSSql, Posgres, (TSql, BI OLAP, MDX), Mongo, Git, SVN, CodeIgnater, Symfony, Yii 2, JiRA, Redmine, Bitbucket, Composer, Rabbit MQ, Amazon (SQS, S3, Transcribe), Docker
vetalb91
Спасибо , просто немного запутался во вложеностях и неправильно указал корень . Все получилось wink.gif еще раз спасибо !
killer8080
Цитата (vetalb91 @ 3.10.2017 - 01:04)
Всем привет подскажите как создать xml документ с такой структурой ?

а разве это корректная структура? Где корневой элемент?
https://www.w3.org/TR/REC-xml/#dt-wellformed
Цитата
2.1 Well-Formed XML Documents

[Definition: A textual object is a well-formed XML document if:]

Taken as a whole, it matches the production labeled document.

It meets all the well-formedness constraints given in this specification.

Each of the parsed entities which is referenced directly or indirectly within the document is well-formed.

Document

[1]    document    ::=    prolog element Misc*
Matching the document production implies that:

It contains one or more elements.

[Definition: There is exactly one element, called the root, or document element, no part of which appears in the content of any other element.] For all other elements, if the start-tag is in the content of another element, the end-tag is in the content of the same element. More simply stated, the elements, delimited by start- and end-tags, nest properly within each other.

[Definition: As a consequence of this, for each non-root element C in the document, there is one other element P in the document such that C is in the content of P, but is not in the content of any other element that is in the content of P. P is referred to as the parent of C, and C as a child of P.]

vetalb91
Я запихнул все в корневой элемент xml в итоге создается вот такой документ:
<?xml version="1.0" encoding="utf-8"?>
<XML>
<HEADER>
<agentId>201</agentId>
<agentname>ООО "XXX"</agentname>
<agentadress>Адрес/agentadress>
<metro></metro>
<coordinate></coordinate>
<creationDate>2017-09-27 21:10:31</creationDate>
</HEADER>
<PRICES>
<priceItems>
<farmItemId>1001508</farmItemId>
<quantity>2</quantity>
<price>143.80</price>
</priceItems>
<priceItems>
<farmItemId>1001508</farmItemId>
<quantity>2</quantity>
<price>143.80</price>
</priceItems>
<priceItems>
<farmItemId>1001508</farmItemId>
<quantity>2</quantity>
<price>143.80</price>
</priceItems>
</PRICES>
</XML>
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.